{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e5490ab7",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.document_loaders import UnstructuredFileLoader\n",
    "from langchain.chains.summarize import load_summarize_chain\n",
    "from langchain.chains.question_answering import load_qa_chain"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37d300f1",
   "metadata": {},
   "source": [
    "### Load Documents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b2b457c7",
   "metadata": {},
   "outputs": [],
   "source": [
    "sm_loader = UnstructuredFileLoader(\"../data/muir_lake_tahoe_in_winter.txt\")\n",
    "sm_doc = sm_loader.load()\n",
    "\n",
    "lg_loader = UnstructuredFileLoader(\"../data/PaulGrahamEssays/worked.txt\")\n",
    "lg_doc = lg_loader.load()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "10ff8c9c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def doc_summary(docs):\n",
    "    print (f'You have {len(docs)} document(s)')\n",
    "    \n",
    "    num_words = sum([len(doc.page_content.split(' ')) for doc in docs])\n",
    "    \n",
    "    print (f'You have roughly {num_words} words in your docs')\n",
    "    print ()\n",
    "    print (f'Preview: \\n{docs[0].page_content.split(\". \")[0]}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9b92effa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You have 1 document(s)\n",
      "You have roughly 2298 words in your docs\n",
      "\n",
      "Preview: \n",
      "The winter glory of the Sierra ! How little is known of it! Californians admire descriptions of the Swiss Alps, reading with breathless interest how ice and snow load their sublime heights, and booming avalanches sweep in glorious array through their crowded forests, while our own icy, snow-laden mountains, with their unrivaled forests, loom unnoticed along our eastern horizon\n"
     ]
    }
   ],
   "source": [
    "doc_summary(sm_doc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fa39e1b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You have 1 document(s)\n",
      "You have roughly 12551 words in your docs\n",
      "\n",
      "Preview: \n",
      "February 2021Before college the two main things I worked on, outside of school,\n",
      "\n",
      "were writing and programming\n"
     ]
    }
   ],
   "source": [
    "doc_summary(lg_doc)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3d922dfa",
   "metadata": {},
   "source": [
    "### Load Your LLM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "daf7e272",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain import OpenAI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e6b576c6",
   "metadata": {
    "hide_input": false
   },
   "outputs": [],
   "source": [
    "OPENAI_API_KEY = '...'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "182a2951",
   "metadata": {},
   "outputs": [],
   "source": [
    "llm = OpenAI(openai_api_key=OPENAI_API_KEY)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6515044",
   "metadata": {},
   "source": [
    "### Summarize: Stuff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "020b276d",
   "metadata": {},
   "outputs": [],
   "source": [
    "chain = load_summarize_chain(llm, chain_type=\"stuff\", verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1ee5d17f",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new StuffDocumentsChain chain...\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"The winter glory of the Sierra ! How little is known of it! Californians admire descriptions of the Swiss Alps, reading with breathless interest how ice and snow load their sublime heights, and booming avalanches sweep in glorious array through their crowded forests, while our own icy, snow-laden mountains, with their unrivaled forests, loom unnoticed along our eastern horizon. True, only mountaineers may penetrate their snow-blocked fastnesses to behold them in all their white wild grandeur, but to every healthy man and woman, and even to children, many of the subalpine valleys and lake-basins, six or seven thousand feet above the sea, remain invitingly open and approachable all winter. With a friend and his two little sons I have just returned from a week of bracing weathering around Lake Tahoe, in which we enjoyed glorious views of winter, fine rolling and sliding in the snow, swimming in the icy lake, and lusty reviving exercise on snow-shoes that kept our pulses dancing right merrily. All the weather was hearty and exhilarating, though varying almost from hour to hour: snowing, blowing, clear and cloudy, but never rigorously cold.\n",
      "\n",
      "This winter has been remarkably mild, the mercury having seldom made a very near approach to zero, even during the coldest nights around the lake, while the average noonday temperature was considerably above the freezing- point. The snow lies deep on the surrounding mountains and about the shores, solid white contrasting with the dark-blue water of the lake, while the forests and canons and the upper glacial fountain hollows are well filled, assuring abundance of summer water for the lakes and streams.\n",
      "\n",
      "According to the record kept by Mr. McKinney, on the west shore of the lake, eight miles above Tahoe City, at an elevation of 6,500 feet above sea-level, the amount of snow, measured as it fell, was twenty-two feet and four inches for the season up to March 20th, with four inches of rain, while an inch or two more of rain and two or three feet of snow will probably fall before the full opening of spring. Last season the snowfall, measured by the same observer, at the same station, was only nine feet and seven inches, while the season before last it was no less than forty seven feet and six inches. The fall about Yosemite Valley, according to my own observations, usually considerably exceeded this. The greater portion of the snow that loads the main summits of the range falls in small crisp flakes and broken crystals; or when accompanied by strong winds at a low temperature, the crystals, instead of being locked together in tufted flakes, are driven against each other and broken into meal and fine dust which darkens the sky like night But down in the forested region, at about the elevation of Lake Tahoe, the greater portion comes gently to the ground, light and feathery, some of the flakes in mild weather being nearly an inch in diameter, and is evenly distributed and kept from drifting to any great extent by Lake Tahoe in Winter. 121 the shelter of the woods. Every tree is loaded with the fairy bloom, bending down the branches, and hushing the singing of the elastic needles. When the storm is over and the sun shines, the dazzling snow at once begins to settle and shift and fall off the trees in miniature avalanches; then the relieved branches spring up and shake themselves dry, and the whole green forest, fed and refreshed, waves and sings again rejoicing. The snow on the ground settles also, and thaws and freezes until it becomes coarsely granulated ice, with all trace of its crystalline snow structure destroyed. This is the present condition of most of the snow on the range. From towards midnight until midday at this time of year a man may walk firmly over the surface, as if on ice, provided the preceding day has been warm and the night frosty.\n",
      "\n",
      "The forested region up to an elevation of about eight thousand feet is generally clear of snow towards the end of May or middle of June; but now (March 28th) the higher canons are still heavily blocked, and the head tributaries of the rivers flow in dark tunnels beneath the icy mass. As warm summer advances, the roof of compacted snow falls in here and there, leaving magnificent arching bridges where it is strongest, over which one may safely ride a horse. All the upper streams are thus buried and bridged every winter, and are seldom completely opened to the light before the end of June or middle of July.\n",
      "\n",
      "Notwithstanding twenty-two feet of snow has fallen here this season, so greatly has it been melted and compacted, the present average depth at a height of 7,500 feet does not exceed seven feet. The drifts in exposed lake hollows and along the lee sides of bald ridges above the timberline are often fifty feet or more in depth, and many of the latter are grandly adorned with overcurling cornices, beneath which pale blue light shimmers with ineffable beauty. But it is in the fountain cirques of the ancient glaciers, beneath the shadows of the highest peaks, that the heaviest and most enduring deposits are stored up. For there the lavish snowfall on the steep converging slopes is shot down in avalanches during or after' every storm, heaping snow on snow to a depth of a hundred feet, or even more at times. These treasured banks are never wholly melted, however hot the summer, but with the few lingering glaciers form perennial fountains for the highest tributaries of the rivers.\n",
      "\n",
      "Few even among Californians have any fair conception of the marvelous abundance of glacier lakes hidden in the fastnesses of our mountains. The snow and some of the glaciers make a telling show, even from the distant lowlands; but not a single stream is visible, nor a hollow where one might hope to find a lake. Nevertheless, wild rivers are falling and sounding in every canon, and all their upper branches are fairly laden with lakes like orchard-trees with fruit. They nestle in rocky nooks and hollows about all the high peaks and in the larger canons, reflecting their stern, rugged beauty and giving charming animation to the bleakest and most forbidding landscapes. From the summit of Red Mountain, a day's journey to the east of Yosemite Valley, forty-two may be seen within a radius of eight or ten miles. The whole number in the Sierra can hardly be less than fifteen hundred, exclusive of the smaller gems, which are innumerable. Perhaps two-thirds of them lie on the west flank of the range, and all are restricted to the alpine and subalpine regions, those which once brightened the lower regions having long since vanished by the filling in of their basins. Lake Tahoe is king of them all, not only in size, but in the surpassing beauty of its shores and waters. It seems a kind of heaven to which the dead lakes of the lowlands had come with their best beauty spiritualized. It lies embosomed in mountains of moderate height near the northern extremity of the high portion of the Lake Tahoe in Winter. 123 range, between the main axis and a spur that puts out on the east side from near the head of the Carson River. Though it is twenty-one miles long by ten wide, and from about five hundred to sixteen hundred feet deep, its basin was once occupied by a glacier which filled it from the bottom to a point high above the present water-level, and being lavishly fed by the snows of the encompassing mountains, crawled slowly, like a mighty river, over the north rim of the basin, crushing and grinding the lower mountains that lay in its way, and it was only at the end of the ice period that this noble lake, at least in anything like its present form, came into existence.\n",
      "\n",
      "Excepting the forests that have sprung up around its shores, the post-glacial changes that have taken place are scarcely appreciable. The sediments carried forward by the inflowing streams at the head of the lake have made a few square miles of meadow-land, and the breaking through of a moraine dam in the canon of the outlet has lowered the lake considerably, leaving shore benches and lines on the rocky promontories to mark the original level. With these comparatively unimportant exceptions, the lake itself and all its grandly sculptured, ice-scored, and moraine-streaked basin exist to-day in just about the condition they presented when first they came to the light towards the close of the Glacial Period.\n",
      "\n",
      "The destructive action of man in clearing away the forests has not as yet effected any very marked change in general views. Perhaps about 150,000,000 feet of lumber for the Comstock mines has thus far been cut from the lake shores. But the business is being pushed so fervently from year to year, almost the entire basin must be stripped ere long of one of its most attractive features. One of the lumber companies at work here has contracted with mine owners to supply 36,000,000 feet of lumber and 60,000 cords of wood this season. It is estimated that the Tahoe basin still contains about 600,000,000 feet of lumber available for the mines.\n",
      "\n",
      "In summer the woods resound with the outlandish noise of loggers and choppers and screaming mills; skiffs and steamboats skim the lovely blue water in work and play; and ever and anon as you thread the groves along shore you come upon groups of gay tourists sauntering about, gathering flowers, or resting luxuriously in the rosiny shade of the pines, some in easy picnic attire, others all ribbons and colors, glaring wildly amid the green leaves and frightening the wondering squirrels and birds. But winter brings rest. At sight of the first snowflake pleasure-seekers flee as from a plague, the ax leaves the woods, and the kind snow heals every scar. Contemplating the basin from any commanding hilltop, only pale curls of smoke seen at wide intervals betoken the existence of human dwellings. Like the bears, the few settlers that remain here are silently \"holed up.\" The snow covers their cabins as if they were bowlders, and when approached only a narrow shoveled-out passage, or tunnel, is found leading to the door. Some of the more enterprising winter dwellers drift about in boats in calm weather, catching trout for the Carson market,â€”for the lake, on account of its great depth, never freezes. They thus earn from thirty to forty dollars a month, and at the same time get rid of lonely dullness. A trapper may also be seen now and then shuffling along the shore on long Norwegian snow-shoes in pursuit of minks, fishers, and otters.\n",
      "\n",
      "In this letter I intended only to say a good word for winter in the mountains, hoping to incite others to come and enjoy it, sketching our excursion to illustrate the ease and comfort with which such snowy winter rambles may be made; but I have written too much I fear about the snow to leave room for more than a thin outline. We went by rail to Lake Tahoe in Winter. 125 Carson, and from there set out by stage for Glenbrook. After ascending on wheels until we reached the snow-line, the driver attached his four horses to a sled, hoping thus to cross the summit, which is less than eight thousand feet high, without much difficulty. But mild weather had softened the snow, and the unfortunate animals, after floundering and wallowing through a mile of it, lay down exhausted with their heels in the air. Then we made our way on foot over to the lake. Next day, on a small steam-tug, we crossed the lake to McKinney's, on the west shore, where we were at home. Here we spent a few health-giving, delightful days, rowing, bathing, racing at lightning speed on snow-shoes down a mountain-side back of the house, and slipping about through the solemn, silent woods. Only the eldest of my companions ventured with me on the steep slopes. This was his first experience on snowshoes, and the several descents he made were the most remarkable specimens of falling locomotion that I ever had the fortune to witness. In shooting down steep declivities the long sled-runner-like shoes have to be kept parallel with firmly braced limbs. My friend, however, heedless of advice, launched himself in wild abandon, bouncing and diving, his limbs and shoes in chaotic entanglement, now in the snow, now in the air, whirling over and over in giddy rolls and somersaults that would shame the most extravagant performances of a circus acrobat. How original and inimitable he was! Wonderfully refreshing and exhilarating his queer capers must have been; for on coming to rest, with his runaway members divorced and lost, he would quietly gather himself, pick out the snow from his neck and ears, and say with preternatural solemnity, \"This, Muir, is the very poetry of motion.\"\n",
      "\n",
      "We also spent some rare evenings by the huge fire in McKinney's old cabin. The log walls are covered with trophies of the chase, for our host has been a great hunter in his day. Two live pet coons were frolicking on the floor while our grand old host smiled benignly and played with them, the firelight gleaming on his weathered face. How big he seems, thus brought into relief, and what a shadow he casts! The fragrant rosiny fire is the very god of the home. No wonder the old nations, with their fresher instincts, had their fireside gods. At last, when a mild snow-storm was blowing, we rowed to the lower end of the lake and completed our excursion by slipping on snow-shoes down the Truckee canon to the railroad.\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "\" This article is a description of a winter trip to Lake Tahoe, California. It highlights the mild winter weather and snow-covered mountains, as well as the abundance of glacier lakes in the Sierra region. The author also mentions the local lumber companies and their destructive effects on the lake's forests, as well as the activities of the few remaining winter dwellers. The article concludes with a description of a snowshoeing excursion down the Truckee canon to the railroad.\""
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chain.run(sm_doc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3e3add98",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new StuffDocumentsChain chain...\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"February 2021Before college the two main things I worked on, outside of school,\n",
      "\n",
      "were writing and programming. I didn't write essays. I wrote what\n",
      "\n",
      "beginning writers were supposed to write then, and probably still\n",
      "\n",
      "are: short stories. My stories were awful. They had hardly any plot,\n",
      "\n",
      "just characters with strong feelings, which I imagined made them\n",
      "\n",
      "deep.The first programs I tried writing were on the IBM 1401 that our\n",
      "\n",
      "school district used for what was then called \"data processing.\"\n",
      "\n",
      "This was in 9th grade, so I was 13 or 14. The school district's\n",
      "\n",
      "1401 happened to be in the basement of our junior high school, and\n",
      "\n",
      "my friend Rich Draves and I got permission to use it. It was like\n",
      "\n",
      "a mini Bond villain's lair down there, with all these alien-looking\n",
      "\n",
      "machines  CPU, disk drives, printer, card reader  sitting up\n",
      "\n",
      "on a raised floor under bright fluorescent lights.The language we used was an early version of Fortran. You had to\n",
      "\n",
      "type programs on punch cards, then stack them in the card reader\n",
      "\n",
      "and press a button to load the program into memory and run it. The\n",
      "\n",
      "result would ordinarily be to print something on the spectacularly\n",
      "\n",
      "loud printer.I was puzzled by the 1401. I couldn't figure out what to do with\n",
      "\n",
      "it. And in retrospect there's not much I could have done with it.\n",
      "\n",
      "The only form of input to programs was data stored on punched cards,\n",
      "\n",
      "and I didn't have any data stored on punched cards. The only other\n",
      "\n",
      "option was to do things that didn't rely on any input, like calculate\n",
      "\n",
      "approximations of pi, but I didn't know enough math to do anything\n",
      "\n",
      "interesting of that type. So I'm not surprised I can't remember any\n",
      "\n",
      "programs I wrote, because they can't have done much. My clearest\n",
      "\n",
      "memory is of the moment I learned it was possible for programs not\n",
      "\n",
      "to terminate, when one of mine didn't. On a machine without\n",
      "\n",
      "time-sharing, this was a social as well as a technical error, as\n",
      "\n",
      "the data center manager's expression made clear.With microcomputers, everything changed. Now you could have a\n",
      "\n",
      "computer sitting right in front of you, on a desk, that could respond\n",
      "\n",
      "to your keystrokes as it was running instead of just churning through\n",
      "\n",
      "a stack of punch cards and then stopping.\n",
      "\n",
      "[1]The first of my friends to get a microcomputer built it himself.\n",
      "\n",
      "It was sold as a kit by Heathkit. I remember vividly how impressed\n",
      "\n",
      "and envious I felt watching him sitting in front of it, typing\n",
      "\n",
      "programs right into the computer.Computers were expensive in those days and it took me years of\n",
      "\n",
      "nagging before I convinced my father to buy one, a TRS-80, in about\n",
      "\n",
      "1980. The gold standard then was the Apple II, but a TRS-80 was\n",
      "\n",
      "good enough. This was when I really started programming. I wrote\n",
      "\n",
      "simple games, a program to predict how high my model rockets would\n",
      "\n",
      "fly, and a word processor that my father used to write at least one\n",
      "\n",
      "book. There was only room in memory for about 2 pages of text, so\n",
      "\n",
      "he'd write 2 pages at a time and then print them out, but it was a\n",
      "\n",
      "lot better than a typewriter.Though I liked programming, I didn't plan to study it in college.\n",
      "\n",
      "In college I was going to study philosophy, which sounded much more\n",
      "\n",
      "powerful. It seemed, to my naive high school self, to be the study\n",
      "\n",
      "of the ultimate truths, compared to which the things studied in\n",
      "\n",
      "other fields would be mere domain knowledge. What I discovered when\n",
      "\n",
      "I got to college was that the other fields took up so much of the\n",
      "\n",
      "space of ideas that there wasn't much left for these supposed\n",
      "\n",
      "ultimate truths. All that seemed left for philosophy were edge cases\n",
      "\n",
      "that people in other fields felt could safely be ignored.I couldn't have put this into words when I was 18. All I knew at\n",
      "\n",
      "the time was that I kept taking philosophy courses and they kept\n",
      "\n",
      "being boring. So I decided to switch to AI.AI was in the air in the mid 1980s, but there were two things\n",
      "\n",
      "especially that made me want to work on it: a novel by Heinlein\n",
      "\n",
      "called The Moon is a Harsh Mistress, which featured an intelligent\n",
      "\n",
      "computer called Mike, and a PBS documentary that showed Terry\n",
      "\n",
      "Winograd using SHRDLU. I haven't tried rereading The Moon is a Harsh\n",
      "\n",
      "Mistress, so I don't know how well it has aged, but when I read it\n",
      "\n",
      "I was drawn entirely into its world. It seemed only a matter of\n",
      "\n",
      "time before we'd have Mike, and when I saw Winograd using SHRDLU,\n",
      "\n",
      "it seemed like that time would be a few years at most. All you had\n",
      "\n",
      "to do was teach SHRDLU more words.There weren't any classes in AI at Cornell then, not even graduate\n",
      "\n",
      "classes, so I started trying to teach myself. Which meant learning\n",
      "\n",
      "Lisp, since in those days Lisp was regarded as the language of AI.\n",
      "\n",
      "The commonly used programming languages then were pretty primitive,\n",
      "\n",
      "and programmers' ideas correspondingly so. The default language at\n",
      "\n",
      "Cornell was a Pascal-like language called PL/I, and the situation\n",
      "\n",
      "was similar elsewhere. Learning Lisp expanded my concept of a program\n",
      "\n",
      "so fast that it was years before I started to have a sense of where\n",
      "\n",
      "the new limits were. This was more like it; this was what I had\n",
      "\n",
      "expected college to do. It wasn't happening in a class, like it was\n",
      "\n",
      "supposed to, but that was ok. For the next couple years I was on a\n",
      "\n",
      "roll. I knew what I was going to do.For my undergraduate thesis, I reverse-engineered SHRDLU. My God\n",
      "\n",
      "did I love working on that program. It was a pleasing bit of code,\n",
      "\n",
      "but what made it even more exciting was my belief  hard to imagine\n",
      "\n",
      "now, but not unique in 1985  that it was already climbing the\n",
      "\n",
      "lower slopes of intelligence.I had gotten into a program at Cornell that didn't make you choose\n",
      "\n",
      "a major. You could take whatever classes you liked, and choose\n",
      "\n",
      "whatever you liked to put on your degree. I of course chose \"Artificial\n",
      "\n",
      "Intelligence.\" When I got the actual physical diploma, I was dismayed\n",
      "\n",
      "to find that the quotes had been included, which made them read as\n",
      "\n",
      "scare-quotes. At the time this bothered me, but now it seems amusingly\n",
      "\n",
      "accurate, for reasons I was about to discover.I applied to 3 grad schools: MIT and Yale, which were renowned for\n",
      "\n",
      "AI at the time, and Harvard, which I'd visited because Rich Draves\n",
      "\n",
      "went there, and was also home to Bill Woods, who'd invented the\n",
      "\n",
      "type of parser I used in my SHRDLU clone. Only Harvard accepted me,\n",
      "\n",
      "so that was where I went.I don't remember the moment it happened, or if there even was a\n",
      "\n",
      "specific moment, but during the first year of grad school I realized\n",
      "\n",
      "that AI, as practiced at the time, was a hoax. By which I mean the\n",
      "\n",
      "sort of AI in which a program that's told \"the dog is sitting on\n",
      "\n",
      "the chair\" translates this into some formal representation and adds\n",
      "\n",
      "it to the list of things it knows.What these programs really showed was that there's a subset of\n",
      "\n",
      "natural language that's a formal language. But a very proper subset.\n",
      "\n",
      "It was clear that there was an unbridgeable gap between what they\n",
      "\n",
      "could do and actually understanding natural language. It was not,\n",
      "\n",
      "in fact, simply a matter of teaching SHRDLU more words. That whole\n",
      "\n",
      "way of doing AI, with explicit data structures representing concepts,\n",
      "\n",
      "was not going to work. Its brokenness did, as so often happens,\n",
      "\n",
      "generate a lot of opportunities to write papers about various\n",
      "\n",
      "band-aids that could be applied to it, but it was never going to\n",
      "\n",
      "get us Mike.So I looked around to see what I could salvage from the wreckage\n",
      "\n",
      "of my plans, and there was Lisp. I knew from experience that Lisp\n",
      "\n",
      "was interesting for its own sake and not just for its association\n",
      "\n",
      "with AI, even though that was the main reason people cared about\n",
      "\n",
      "it at the time. So I decided to focus on Lisp. In fact, I decided\n",
      "\n",
      "to write a book about Lisp hacking. It's scary to think how little\n",
      "\n",
      "I knew about Lisp hacking when I started writing that book. But\n",
      "\n",
      "there's nothing like writing a book about something to help you\n",
      "\n",
      "learn it. The book, On Lisp, wasn't published till 1993, but I wrote\n",
      "\n",
      "much of it in grad school.Computer Science is an uneasy alliance between two halves, theory\n",
      "\n",
      "and systems. The theory people prove things, and the systems people\n",
      "\n",
      "build things. I wanted to build things. I had plenty of respect for\n",
      "\n",
      "theory  indeed, a sneaking suspicion that it was the more admirable\n",
      "\n",
      "of the two halves  but building things seemed so much more exciting.The problem with systems work, though, was that it didn't last.\n",
      "\n",
      "Any program you wrote today, no matter how good, would be obsolete\n",
      "\n",
      "in a couple decades at best. People might mention your software in\n",
      "\n",
      "footnotes, but no one would actually use it. And indeed, it would\n",
      "\n",
      "seem very feeble work. Only people with a sense of the history of\n",
      "\n",
      "the field would even realize that, in its time, it had been good.There were some surplus Xerox Dandelions floating around the computer\n",
      "\n",
      "lab at one point. Anyone who wanted one to play around with could\n",
      "\n",
      "have one. I was briefly tempted, but they were so slow by present\n",
      "\n",
      "standards; what was the point? No one else wanted one either, so\n",
      "\n",
      "off they went. That was what happened to systems work.I wanted not just to build things, but to build things that would\n",
      "\n",
      "last.In this dissatisfied state I went in 1988 to visit Rich Draves at\n",
      "\n",
      "CMU, where he was in grad school. One day I went to visit the\n",
      "\n",
      "Carnegie Institute, where I'd spent a lot of time as a kid. While\n",
      "\n",
      "looking at a painting there I realized something that might seem\n",
      "\n",
      "obvious, but was a big surprise to me. There, right on the wall,\n",
      "\n",
      "was something you could make that would last. Paintings didn't\n",
      "\n",
      "become obsolete. Some of the best ones were hundreds of years old.And moreover this was something you could make a living doing. Not\n",
      "\n",
      "as easily as you could by writing software, of course, but I thought\n",
      "\n",
      "if you were really industrious and lived really cheaply, it had to\n",
      "\n",
      "be possible to make enough to survive. And as an artist you could\n",
      "\n",
      "be truly independent. You wouldn't have a boss, or even need to get\n",
      "\n",
      "research funding.I had always liked looking at paintings. Could I make them? I had\n",
      "\n",
      "no idea. I'd never imagined it was even possible. I knew intellectually\n",
      "\n",
      "that people made art  that it didn't just appear spontaneously\n",
      "\n",
      " but it was as if the people who made it were a different species.\n",
      "\n",
      "They either lived long ago or were mysterious geniuses doing strange\n",
      "\n",
      "things in profiles in Life magazine. The idea of actually being\n",
      "\n",
      "able to make art, to put that verb before that noun, seemed almost\n",
      "\n",
      "miraculous.That fall I started taking art classes at Harvard. Grad students\n",
      "\n",
      "could take classes in any department, and my advisor, Tom Cheatham,\n",
      "\n",
      "was very easy going. If he even knew about the strange classes I\n",
      "\n",
      "was taking, he never said anything.So now I was in a PhD program in computer science, yet planning to\n",
      "\n",
      "be an artist, yet also genuinely in love with Lisp hacking and\n",
      "\n",
      "working away at On Lisp. In other words, like many a grad student,\n",
      "\n",
      "I was working energetically on multiple projects that were not my\n",
      "\n",
      "thesis.I didn't see a way out of this situation. I didn't want to drop out\n",
      "\n",
      "of grad school, but how else was I going to get out? I remember\n",
      "\n",
      "when my friend Robert Morris got kicked out of Cornell for writing\n",
      "\n",
      "the internet worm of 1988, I was envious that he'd found such a\n",
      "\n",
      "spectacular way to get out of grad school.Then one day in April 1990 a crack appeared in the wall. I ran into\n",
      "\n",
      "professor Cheatham and he asked if I was far enough along to graduate\n",
      "\n",
      "that June. I didn't have a word of my dissertation written, but in\n",
      "\n",
      "what must have been the quickest bit of thinking in my life, I\n",
      "\n",
      "decided to take a shot at writing one in the 5 weeks or so that\n",
      "\n",
      "remained before the deadline, reusing parts of On Lisp where I\n",
      "\n",
      "could, and I was able to respond, with no perceptible delay \"Yes,\n",
      "\n",
      "I think so. I'll give you something to read in a few days.\"I picked applications of continuations as the topic. In retrospect\n",
      "\n",
      "I should have written about macros and embedded languages. There's\n",
      "\n",
      "a whole world there that's barely been explored. But all I wanted\n",
      "\n",
      "was to get out of grad school, and my rapidly written dissertation\n",
      "\n",
      "sufficed, just barely.Meanwhile I was applying to art schools. I applied to two: RISD in\n",
      "\n",
      "the US, and the Accademia di Belli Arti in Florence, which, because\n",
      "\n",
      "it was the oldest art school, I imagined would be good. RISD accepted\n",
      "\n",
      "me, and I never heard back from the Accademia, so off to Providence\n",
      "\n",
      "I went.I'd applied for the BFA program at RISD, which meant in effect that\n",
      "\n",
      "I had to go to college again. This was not as strange as it sounds,\n",
      "\n",
      "because I was only 25, and art schools are full of people of different\n",
      "\n",
      "ages. RISD counted me as a transfer sophomore and said I had to do\n",
      "\n",
      "the foundation that summer. The foundation means the classes that\n",
      "\n",
      "everyone has to take in fundamental subjects like drawing, color,\n",
      "\n",
      "and design.Toward the end of the summer I got a big surprise: a letter from\n",
      "\n",
      "the Accademia, which had been delayed because they'd sent it to\n",
      "\n",
      "Cambridge England instead of Cambridge Massachusetts, inviting me\n",
      "\n",
      "to take the entrance exam in Florence that fall. This was now only\n",
      "\n",
      "weeks away. My nice landlady let me leave my stuff in her attic. I\n",
      "\n",
      "had some money saved from consulting work I'd done in grad school;\n",
      "\n",
      "there was probably enough to last a year if I lived cheaply. Now\n",
      "\n",
      "all I had to do was learn Italian.Only stranieri (foreigners) had to take this entrance exam. In\n",
      "\n",
      "retrospect it may well have been a way of excluding them, because\n",
      "\n",
      "there were so many stranieri attracted by the idea of studying\n",
      "\n",
      "art in Florence that the Italian students would otherwise have been\n",
      "\n",
      "outnumbered. I was in decent shape at painting and drawing from the\n",
      "\n",
      "RISD foundation that summer, but I still don't know how I managed\n",
      "\n",
      "to pass the written exam. I remember that I answered the essay\n",
      "\n",
      "question by writing about Cezanne, and that I cranked up the\n",
      "\n",
      "intellectual level as high as I could to make the most of my limited\n",
      "\n",
      "vocabulary.\n",
      "\n",
      "[2]I'm only up to age 25 and already there are such conspicuous patterns.\n",
      "\n",
      "Here I was, yet again about to attend some august institution in\n",
      "\n",
      "the hopes of learning about some prestigious subject, and yet again\n",
      "\n",
      "about to be disappointed. The students and faculty in the painting\n",
      "\n",
      "department at the Accademia were the nicest people you could imagine,\n",
      "\n",
      "but they had long since arrived at an arrangement whereby the\n",
      "\n",
      "students wouldn't require the faculty to teach anything, and in\n",
      "\n",
      "return the faculty wouldn't require the students to learn anything.\n",
      "\n",
      "And at the same time all involved would adhere outwardly to the\n",
      "\n",
      "conventions of a 19th century atelier. We actually had one of those\n",
      "\n",
      "little stoves, fed with kindling, that you see in 19th century\n",
      "\n",
      "studio paintings, and a nude model sitting as close to it as possible\n",
      "\n",
      "without getting burned. Except hardly anyone else painted her besides\n",
      "\n",
      "me. The rest of the students spent their time chatting or occasionally\n",
      "\n",
      "trying to imitate things they'd seen in American art magazines.Our model turned out to live just down the street from me. She made\n",
      "\n",
      "a living from a combination of modelling and making fakes for a\n",
      "\n",
      "local antique dealer. She'd copy an obscure old painting out of a\n",
      "\n",
      "book, and then he'd take the copy and maltreat it to make it look\n",
      "\n",
      "old.\n",
      "\n",
      "[3]While I was a student at the Accademia I started painting still\n",
      "\n",
      "lives in my bedroom at night. These paintings were tiny, because\n",
      "\n",
      "the room was, and because I painted them on leftover scraps of\n",
      "\n",
      "canvas, which was all I could afford at the time. Painting still\n",
      "\n",
      "lives is different from painting people, because the subject, as\n",
      "\n",
      "its name suggests, can't move. People can't sit for more than about\n",
      "\n",
      "15 minutes at a time, and when they do they don't sit very still.\n",
      "\n",
      "So the traditional m.o. for painting people is to know how to paint\n",
      "\n",
      "a generic person, which you then modify to match the specific person\n",
      "\n",
      "you're painting. Whereas a still life you can, if you want, copy\n",
      "\n",
      "pixel by pixel from what you're seeing. You don't want to stop\n",
      "\n",
      "there, of course, or you get merely photographic accuracy, and what\n",
      "\n",
      "makes a still life interesting is that it's been through a head.\n",
      "\n",
      "You want to emphasize the visual cues that tell you, for example,\n",
      "\n",
      "that the reason the color changes suddenly at a certain point is\n",
      "\n",
      "that it's the edge of an object. By subtly emphasizing such things\n",
      "\n",
      "you can make paintings that are more realistic than photographs not\n",
      "\n",
      "just in some metaphorical sense, but in the strict information-theoretic\n",
      "\n",
      "sense.\n",
      "\n",
      "[4]I liked painting still lives because I was curious about what I was\n",
      "\n",
      "seeing. In everyday life, we aren't consciously aware of much we're\n",
      "\n",
      "seeing. Most visual perception is handled by low-level processes\n",
      "\n",
      "that merely tell your brain \"that's a water droplet\" without telling\n",
      "\n",
      "you details like where the lightest and darkest points are, or\n",
      "\n",
      "\"that's a bush\" without telling you the shape and position of every\n",
      "\n",
      "leaf. This is a feature of brains, not a bug. In everyday life it\n",
      "\n",
      "would be distracting to notice every leaf on every bush. But when\n",
      "\n",
      "you have to paint something, you have to look more closely, and\n",
      "\n",
      "when you do there's a lot to see. You can still be noticing new\n",
      "\n",
      "things after days of trying to paint something people usually take\n",
      "\n",
      "for granted, just as you can  after\n",
      "\n",
      "days of trying to write an essay about something people usually\n",
      "\n",
      "take for granted.This is not the only way to paint. I'm not 100% sure it's even a\n",
      "\n",
      "good way to paint. But it seemed a good enough bet to be worth\n",
      "\n",
      "trying.Our teacher, professor Ulivi, was a nice guy. He could see I worked\n",
      "\n",
      "hard, and gave me a good grade, which he wrote down in a sort of\n",
      "\n",
      "passport each student had. But the Accademia wasn't teaching me\n",
      "\n",
      "anything except Italian, and my money was running out, so at the\n",
      "\n",
      "end of the first year I went back to the US.I wanted to go back to RISD, but I was now broke and RISD was very\n",
      "\n",
      "expensive, so I decided to get a job for a year and then return to\n",
      "\n",
      "RISD the next fall. I got one at a company called Interleaf, which\n",
      "\n",
      "made software for creating documents. You mean like Microsoft Word?\n",
      "\n",
      "Exactly. That was how I learned that low end software tends to eat\n",
      "\n",
      "high end software. But Interleaf still had a few years to live yet.\n",
      "\n",
      "[5]Interleaf had done something pretty bold. Inspired by Emacs, they'd\n",
      "\n",
      "added a scripting language, and even made the scripting language a\n",
      "\n",
      "dialect of Lisp. Now they wanted a Lisp hacker to write things in\n",
      "\n",
      "it. This was the closest thing I've had to a normal job, and I\n",
      "\n",
      "hereby apologize to my boss and coworkers, because I was a bad\n",
      "\n",
      "employee. Their Lisp was the thinnest icing on a giant C cake, and\n",
      "\n",
      "since I didn't know C and didn't want to learn it, I never understood\n",
      "\n",
      "most of the software. Plus I was terribly irresponsible. This was\n",
      "\n",
      "back when a programming job meant showing up every day during certain\n",
      "\n",
      "working hours. That seemed unnatural to me, and on this point the\n",
      "\n",
      "rest of the world is coming around to my way of thinking, but at\n",
      "\n",
      "the time it caused a lot of friction. Toward the end of the year I\n",
      "\n",
      "spent much of my time surreptitiously working on On Lisp, which I\n",
      "\n",
      "had by this time gotten a contract to publish.The good part was that I got paid huge amounts of money, especially\n",
      "\n",
      "by art student standards. In Florence, after paying my part of the\n",
      "\n",
      "rent, my budget for everything else had been $7 a day. Now I was\n",
      "\n",
      "getting paid more than 4 times that every hour, even when I was\n",
      "\n",
      "just sitting in a meeting. By living cheaply I not only managed to\n",
      "\n",
      "save enough to go back to RISD, but also paid off my college loans.I learned some useful things at Interleaf, though they were mostly\n",
      "\n",
      "about what not to do. I learned that it's better for technology\n",
      "\n",
      "companies to be run by product people than sales people (though\n",
      "\n",
      "sales is a real skill and people who are good at it are really good\n",
      "\n",
      "at it), that it leads to bugs when code is edited by too many people,\n",
      "\n",
      "that cheap office space is no bargain if it's depressing, that\n",
      "\n",
      "planned meetings are inferior to corridor conversations, that big,\n",
      "\n",
      "bureaucratic customers are a dangerous source of money, and that\n",
      "\n",
      "there's not much overlap between conventional office hours and the\n",
      "\n",
      "optimal time for hacking, or conventional offices and the optimal\n",
      "\n",
      "place for it.But the most important thing I learned, and which I used in both\n",
      "\n",
      "Viaweb and Y Combinator, is that the low end eats the high end:\n",
      "\n",
      "that it's good to be the \"entry level\" option, even though that\n",
      "\n",
      "will be less prestigious, because if you're not, someone else will\n",
      "\n",
      "be, and will squash you against the ceiling. Which in turn means\n",
      "\n",
      "that prestige is a danger sign.When I left to go back to RISD the next fall, I arranged to do\n",
      "\n",
      "freelance work for the group that did projects for customers, and\n",
      "\n",
      "this was how I survived for the next several years. When I came\n",
      "\n",
      "back to visit for a project later on, someone told me about a new\n",
      "\n",
      "thing called HTML, which was, as he described it, a derivative of\n",
      "\n",
      "SGML. Markup language enthusiasts were an occupational hazard at\n",
      "\n",
      "Interleaf and I ignored him, but this HTML thing later became a big\n",
      "\n",
      "part of my life.In the fall of 1992 I moved back to Providence to continue at RISD.\n",
      "\n",
      "The foundation had merely been intro stuff, and the Accademia had\n",
      "\n",
      "been a (very civilized) joke. Now I was going to see what real art\n",
      "\n",
      "school was like. But alas it was more like the Accademia than not.\n",
      "\n",
      "Better organized, certainly, and a lot more expensive, but it was\n",
      "\n",
      "now becoming clear that art school did not bear the same relationship\n",
      "\n",
      "to art that medical school bore to medicine. At least not the\n",
      "\n",
      "painting department. The textile department, which my next door\n",
      "\n",
      "neighbor belonged to, seemed to be pretty rigorous. No doubt\n",
      "\n",
      "illustration and architecture were too. But painting was post-rigorous.\n",
      "\n",
      "Painting students were supposed to express themselves, which to the\n",
      "\n",
      "more worldly ones meant to try to cook up some sort of distinctive\n",
      "\n",
      "signature style.A signature style is the visual equivalent of what in show business\n",
      "\n",
      "is known as a \"schtick\": something that immediately identifies the\n",
      "\n",
      "work as yours and no one else's. For example, when you see a painting\n",
      "\n",
      "that looks like a certain kind of cartoon, you know it's by Roy\n",
      "\n",
      "Lichtenstein. So if you see a big painting of this type hanging in\n",
      "\n",
      "the apartment of a hedge fund manager, you know he paid millions\n",
      "\n",
      "of dollars for it. That's not always why artists have a signature\n",
      "\n",
      "style, but it's usually why buyers pay a lot for such work.\n",
      "\n",
      "[6]There were plenty of earnest students too: kids who \"could draw\"\n",
      "\n",
      "in high school, and now had come to what was supposed to be the\n",
      "\n",
      "best art school in the country, to learn to draw even better. They\n",
      "\n",
      "tended to be confused and demoralized by what they found at RISD,\n",
      "\n",
      "but they kept going, because painting was what they did. I was not\n",
      "\n",
      "one of the kids who could draw in high school, but at RISD I was\n",
      "\n",
      "definitely closer to their tribe than the tribe of signature style\n",
      "\n",
      "seekers.I learned a lot in the color class I took at RISD, but otherwise I\n",
      "\n",
      "was basically teaching myself to paint, and I could do that for\n",
      "\n",
      "free. So in 1993 I dropped out. I hung around Providence for a bit,\n",
      "\n",
      "and then my college friend Nancy Parmet did me a big favor. A\n",
      "\n",
      "rent-controlled apartment in a building her mother owned in New\n",
      "\n",
      "York was becoming vacant. Did I want it? It wasn't much more than\n",
      "\n",
      "my current place, and New York was supposed to be where the artists\n",
      "\n",
      "were. So yes, I wanted it!\n",
      "\n",
      "[7]Asterix comics begin by zooming in on a tiny corner of Roman Gaul\n",
      "\n",
      "that turns out not to be controlled by the Romans. You can do\n",
      "\n",
      "something similar on a map of New York City: if you zoom in on the\n",
      "\n",
      "Upper East Side, there's a tiny corner that's not rich, or at least\n",
      "\n",
      "wasn't in 1993. It's called Yorkville, and that was my new home.\n",
      "\n",
      "Now I was a New York artist  in the strictly technical sense of\n",
      "\n",
      "making paintings and living in New York.I was nervous about money, because I could sense that Interleaf was\n",
      "\n",
      "on the way down. Freelance Lisp hacking work was very rare, and I\n",
      "\n",
      "didn't want to have to program in another language, which in those\n",
      "\n",
      "days would have meant C++ if I was lucky. So with my unerring nose\n",
      "\n",
      "for financial opportunity, I decided to write another book on Lisp.\n",
      "\n",
      "This would be a popular book, the sort of book that could be used\n",
      "\n",
      "as a textbook. I imagined myself living frugally off the royalties\n",
      "\n",
      "and spending all my time painting. (The painting on the cover of\n",
      "\n",
      "this book, ANSI Common Lisp, is one that I painted around this\n",
      "\n",
      "time.)The best thing about New York for me was the presence of Idelle and\n",
      "\n",
      "Julian Weber. Idelle Weber was a painter, one of the early\n",
      "\n",
      "photorealists, and I'd taken her painting class at Harvard. I've\n",
      "\n",
      "never known a teacher more beloved by her students. Large numbers\n",
      "\n",
      "of former students kept in touch with her, including me. After I\n",
      "\n",
      "moved to New York I became her de facto studio assistant.She liked to paint on big, square canvases, 4 to 5 feet on a side.\n",
      "\n",
      "One day in late 1994 as I was stretching one of these monsters there\n",
      "\n",
      "was something on the radio about a famous fund manager. He wasn't\n",
      "\n",
      "that much older than me, and was super rich. The thought suddenly\n",
      "\n",
      "occurred to me: why don't I become rich? Then I'll be able to work\n",
      "\n",
      "on whatever I want.Meanwhile I'd been hearing more and more about this new thing called\n",
      "\n",
      "the World Wide Web. Robert Morris showed it to me when I visited\n",
      "\n",
      "him in Cambridge, where he was now in grad school at Harvard. It\n",
      "\n",
      "seemed to me that the web would be a big deal. I'd seen what graphical\n",
      "\n",
      "user interfaces had done for the popularity of microcomputers. It\n",
      "\n",
      "seemed like the web would do the same for the internet.If I wanted to get rich, here was the next train leaving the station.\n",
      "\n",
      "I was right about that part. What I got wrong was the idea. I decided\n",
      "\n",
      "we should start a company to put art galleries online. I can't\n",
      "\n",
      "honestly say, after reading so many Y Combinator applications, that\n",
      "\n",
      "this was the worst startup idea ever, but it was up there. Art\n",
      "\n",
      "galleries didn't want to be online, and still don't, not the fancy\n",
      "\n",
      "ones. That's not how they sell. I wrote some software to generate\n",
      "\n",
      "web sites for galleries, and Robert wrote some to resize images and\n",
      "\n",
      "set up an http server to serve the pages. Then we tried to sign up\n",
      "\n",
      "galleries. To call this a difficult sale would be an understatement.\n",
      "\n",
      "It was difficult to give away. A few galleries let us make sites\n",
      "\n",
      "for them for free, but none paid us.Then some online stores started to appear, and I realized that\n",
      "\n",
      "except for the order buttons they were identical to the sites we'd\n",
      "\n",
      "been generating for galleries. This impressive-sounding thing called\n",
      "\n",
      "an \"internet storefront\" was something we already knew how to build.So in the summer of 1995, after I submitted the camera-ready copy\n",
      "\n",
      "of ANSI Common Lisp to the publishers, we started trying to write\n",
      "\n",
      "software to build online stores. At first this was going to be\n",
      "\n",
      "normal desktop software, which in those days meant Windows software.\n",
      "\n",
      "That was an alarming prospect, because neither of us knew how to\n",
      "\n",
      "write Windows software or wanted to learn. We lived in the Unix\n",
      "\n",
      "world. But we decided we'd at least try writing a prototype store\n",
      "\n",
      "builder on Unix. Robert wrote a shopping cart, and I wrote a new\n",
      "\n",
      "site generator for stores  in Lisp, of course.We were working out of Robert's apartment in Cambridge. His roommate\n",
      "\n",
      "was away for big chunks of time, during which I got to sleep in his\n",
      "\n",
      "room. For some reason there was no bed frame or sheets, just a\n",
      "\n",
      "mattress on the floor. One morning as I was lying on this mattress\n",
      "\n",
      "I had an idea that made me sit up like a capital L. What if we ran\n",
      "\n",
      "the software on the server, and let users control it by clicking\n",
      "\n",
      "on links? Then we'd never have to write anything to run on users'\n",
      "\n",
      "computers. We could generate the sites on the same server we'd serve\n",
      "\n",
      "them from. Users wouldn't need anything more than a browser.This kind of software, known as a web app, is common now, but at\n",
      "\n",
      "the time it wasn't clear that it was even possible. To find out,\n",
      "\n",
      "we decided to try making a version of our store builder that you\n",
      "\n",
      "could control through the browser. A couple days later, on August\n",
      "\n",
      "12, we had one that worked. The UI was horrible, but it proved you\n",
      "\n",
      "could build a whole store through the browser, without any client\n",
      "\n",
      "software or typing anything into the command line on the server.Now we felt like we were really onto something. I had visions of a\n",
      "\n",
      "whole new generation of software working this way. You wouldn't\n",
      "\n",
      "need versions, or ports, or any of that crap. At Interleaf there\n",
      "\n",
      "had been a whole group called Release Engineering that seemed to\n",
      "\n",
      "be at least as big as the group that actually wrote the software.\n",
      "\n",
      "Now you could just update the software right on the server.We started a new company we called Viaweb, after the fact that our\n",
      "\n",
      "software worked via the web, and we got $10,000 in seed funding\n",
      "\n",
      "from Idelle's husband Julian. In return for that and doing the\n",
      "\n",
      "initial legal work and giving us business advice, we gave him 10%\n",
      "\n",
      "of the company. Ten years later this deal became the model for Y\n",
      "\n",
      "Combinator's. We knew founders needed something like this, because\n",
      "\n",
      "we'd needed it ourselves.At this stage I had a negative net worth, because the thousand\n",
      "\n",
      "dollars or so I had in the bank was more than counterbalanced by\n",
      "\n",
      "what I owed the government in taxes. (Had I diligently set aside\n",
      "\n",
      "the proper proportion of the money I'd made consulting for Interleaf?\n",
      "\n",
      "No, I had not.) So although Robert had his graduate student stipend,\n",
      "\n",
      "I needed that seed funding to live on.We originally hoped to launch in September, but we got more ambitious\n",
      "\n",
      "about the software as we worked on it. Eventually we managed to\n",
      "\n",
      "build a WYSIWYG site builder, in the sense that as you were creating\n",
      "\n",
      "pages, they looked exactly like the static ones that would be\n",
      "\n",
      "generated later, except that instead of leading to static pages,\n",
      "\n",
      "the links all referred to closures stored in a hash table on the\n",
      "\n",
      "server.It helped to have studied art, because the main goal of an online\n",
      "\n",
      "store builder is to make users look legit, and the key to looking\n",
      "\n",
      "legit is high production values. If you get page layouts and fonts\n",
      "\n",
      "and colors right, you can make a guy running a store out of his\n",
      "\n",
      "bedroom look more legit than a big company.(If you're curious why my site looks so old-fashioned, it's because\n",
      "\n",
      "it's still made with this software. It may look clunky today, but\n",
      "\n",
      "in 1996 it was the last word in slick.)In September, Robert rebelled. \"We've been working on this for a\n",
      "\n",
      "month,\" he said, \"and it's still not done.\" This is funny in\n",
      "\n",
      "retrospect, because he would still be working on it almost 3 years\n",
      "\n",
      "later. But I decided it might be prudent to recruit more programmers,\n",
      "\n",
      "and I asked Robert who else in grad school with him was really good.\n",
      "\n",
      "He recommended Trevor Blackwell, which surprised me at first, because\n",
      "\n",
      "at that point I knew Trevor mainly for his plan to reduce everything\n",
      "\n",
      "in his life to a stack of notecards, which he carried around with\n",
      "\n",
      "him. But Rtm was right, as usual. Trevor turned out to be a\n",
      "\n",
      "frighteningly effective hacker.It was a lot of fun working with Robert and Trevor. They're the two\n",
      "\n",
      "most independent-minded people\n",
      "\n",
      "I know, and in completely different\n",
      "\n",
      "ways. If you could see inside Rtm's brain it would look like a\n",
      "\n",
      "colonial New England church, and if you could see inside Trevor's\n",
      "\n",
      "it would look like the worst excesses of Austrian Rococo.We opened for business, with 6 stores, in January 1996. It was just\n",
      "\n",
      "as well we waited a few months, because although we worried we were\n",
      "\n",
      "late, we were actually almost fatally early. There was a lot of\n",
      "\n",
      "talk in the press then about ecommerce, but not many people actually\n",
      "\n",
      "wanted online stores.\n",
      "\n",
      "[8]There were three main parts to the software: the editor, which\n",
      "\n",
      "people used to build sites and which I wrote, the shopping cart,\n",
      "\n",
      "which Robert wrote, and the manager, which kept track of orders and\n",
      "\n",
      "statistics, and which Trevor wrote. In its time, the editor was one\n",
      "\n",
      "of the best general-purpose site builders. I kept the code tight\n",
      "\n",
      "and didn't have to integrate with any other software except Robert's\n",
      "\n",
      "and Trevor's, so it was quite fun to work on. If all I'd had to do\n",
      "\n",
      "was work on this software, the next 3 years would have been the\n",
      "\n",
      "easiest of my life. Unfortunately I had to do a lot more, all of\n",
      "\n",
      "it stuff I was worse at than programming, and the next 3 years were\n",
      "\n",
      "instead the most stressful.There were a lot of startups making ecommerce software in the second\n",
      "\n",
      "half of the 90s. We were determined to be the Microsoft Word, not\n",
      "\n",
      "the Interleaf. Which meant being easy to use and inexpensive. It\n",
      "\n",
      "was lucky for us that we were poor, because that caused us to make\n",
      "\n",
      "Viaweb even more inexpensive than we realized. We charged $100 a\n",
      "\n",
      "month for a small store and $300 a month for a big one. This low\n",
      "\n",
      "price was a big attraction, and a constant thorn in the sides of\n",
      "\n",
      "competitors, but it wasn't because of some clever insight that we\n",
      "\n",
      "set the price low. We had no idea what businesses paid for things.\n",
      "\n",
      "$300 a month seemed like a lot of money to us.We did a lot of things right by accident like that. For example,\n",
      "\n",
      "we did what's now called \"doing things that\n",
      "\n",
      "don't scale,\" although\n",
      "\n",
      "at the time we would have described it as \"being so lame that we're\n",
      "\n",
      "driven to the most desperate measures to get users.\" The most common\n",
      "\n",
      "of which was building stores for them. This seemed particularly\n",
      "\n",
      "humiliating, since the whole raison d'etre of our software was that\n",
      "\n",
      "people could use it to make their own stores. But anything to get\n",
      "\n",
      "users.We learned a lot more about retail than we wanted to know. For\n",
      "\n",
      "example, that if you could only have a small image of a man's shirt\n",
      "\n",
      "(and all images were small then by present standards), it was better\n",
      "\n",
      "to have a closeup of the collar than a picture of the whole shirt.\n",
      "\n",
      "The reason I remember learning this was that it meant I had to\n",
      "\n",
      "rescan about 30 images of men's shirts. My first set of scans were\n",
      "\n",
      "so beautiful too.Though this felt wrong, it was exactly the right thing to be doing.\n",
      "\n",
      "Building stores for users taught us about retail, and about how it\n",
      "\n",
      "felt to use our software. I was initially both mystified and repelled\n",
      "\n",
      "by \"business\" and thought we needed a \"business person\" to be in\n",
      "\n",
      "charge of it, but once we started to get users, I was converted,\n",
      "\n",
      "in much the same way I was converted to\n",
      "\n",
      "fatherhood once I had kids.\n",
      "\n",
      "Whatever users wanted, I was all theirs. Maybe one day we'd have\n",
      "\n",
      "so many users that I couldn't scan their images for them, but in\n",
      "\n",
      "the meantime there was nothing more important to do.Another thing I didn't get at the time is that\n",
      "\n",
      "growth rate is the\n",
      "\n",
      "ultimate test of a startup. Our growth rate was fine. We had about\n",
      "\n",
      "70 stores at the end of 1996 and about 500 at the end of 1997. I\n",
      "\n",
      "mistakenly thought the thing that mattered was the absolute number\n",
      "\n",
      "of users. And that is the thing that matters in the sense that\n",
      "\n",
      "that's how much money you're making, and if you're not making enough,\n",
      "\n",
      "you might go out of business. But in the long term the growth rate\n",
      "\n",
      "takes care of the absolute number. If we'd been a startup I was\n",
      "\n",
      "advising at Y Combinator, I would have said: Stop being so stressed\n",
      "\n",
      "out, because you're doing fine. You're growing 7x a year. Just don't\n",
      "\n",
      "hire too many more people and you'll soon be profitable, and then\n",
      "\n",
      "you'll control your own destiny.Alas I hired lots more people, partly because our investors wanted\n",
      "\n",
      "me to, and partly because that's what startups did during the\n",
      "\n",
      "Internet Bubble. A company with just a handful of employees would\n",
      "\n",
      "have seemed amateurish. So we didn't reach breakeven until about\n",
      "\n",
      "when Yahoo bought us in the summer of 1998. Which in turn meant we\n",
      "\n",
      "were at the mercy of investors for the entire life of the company.\n",
      "\n",
      "And since both we and our investors were noobs at startups, the\n",
      "\n",
      "result was a mess even by startup standards.It was a huge relief when Yahoo bought us. In principle our Viaweb\n",
      "\n",
      "stock was valuable. It was a share in a business that was profitable\n",
      "\n",
      "and growing rapidly. But it didn't feel very valuable to me; I had\n",
      "\n",
      "no idea how to value a business, but I was all too keenly aware of\n",
      "\n",
      "the near-death experiences we seemed to have every few months. Nor\n",
      "\n",
      "had I changed my grad student lifestyle significantly since we\n",
      "\n",
      "started. So when Yahoo bought us it felt like going from rags to\n",
      "\n",
      "riches. Since we were going to California, I bought a car, a yellow\n",
      "\n",
      "1998 VW GTI. I remember thinking that its leather seats alone were\n",
      "\n",
      "by far the most luxurious thing I owned.The next year, from the summer of 1998 to the summer of 1999, must\n",
      "\n",
      "have been the least productive of my life. I didn't realize it at\n",
      "\n",
      "the time, but I was worn out from the effort and stress of running\n",
      "\n",
      "Viaweb. For a while after I got to California I tried to continue\n",
      "\n",
      "my usual m.o. of programming till 3 in the morning, but fatigue\n",
      "\n",
      "combined with Yahoo's prematurely aged\n",
      "\n",
      "culture and grim cube farm\n",
      "\n",
      "in Santa Clara gradually dragged me down. After a few months it\n",
      "\n",
      "felt disconcertingly like working at Interleaf.Yahoo had given us a lot of options when they bought us. At the\n",
      "\n",
      "time I thought Yahoo was so overvalued that they'd never be worth\n",
      "\n",
      "anything, but to my astonishment the stock went up 5x in the next\n",
      "\n",
      "year. I hung on till the first chunk of options vested, then in the\n",
      "\n",
      "summer of 1999 I left. It had been so long since I'd painted anything\n",
      "\n",
      "that I'd half forgotten why I was doing this. My brain had been\n",
      "\n",
      "entirely full of software and men's shirts for 4 years. But I had\n",
      "\n",
      "done this to get rich so I could paint, I reminded myself, and now\n",
      "\n",
      "I was rich, so I should go paint.When I said I was leaving, my boss at Yahoo had a long conversation\n",
      "\n",
      "with me about my plans. I told him all about the kinds of pictures\n",
      "\n",
      "I wanted to paint. At the time I was touched that he took such an\n",
      "\n",
      "interest in me. Now I realize it was because he thought I was lying.\n",
      "\n",
      "My options at that point were worth about $2 million a month. If I\n",
      "\n",
      "was leaving that kind of money on the table, it could only be to\n",
      "\n",
      "go and start some new startup, and if I did, I might take people\n",
      "\n",
      "with me. This was the height of the Internet Bubble, and Yahoo was\n",
      "\n",
      "ground zero of it. My boss was at that moment a billionaire. Leaving\n",
      "\n",
      "then to start a new startup must have seemed to him an insanely,\n",
      "\n",
      "and yet also plausibly, ambitious plan.But I really was quitting to paint, and I started immediately.\n",
      "\n",
      "There was no time to lose. I'd already burned 4 years getting rich.\n",
      "\n",
      "Now when I talk to founders who are leaving after selling their\n",
      "\n",
      "companies, my advice is always the same: take a vacation. That's\n",
      "\n",
      "what I should have done, just gone off somewhere and done nothing\n",
      "\n",
      "for a month or two, but the idea never occurred to me.So I tried to paint, but I just didn't seem to have any energy or\n",
      "\n",
      "ambition. Part of the problem was that I didn't know many people\n",
      "\n",
      "in California. I'd compounded this problem by buying a house up in\n",
      "\n",
      "the Santa Cruz Mountains, with a beautiful view but miles from\n",
      "\n",
      "anywhere. I stuck it out for a few more months, then in desperation\n",
      "\n",
      "I went back to New York, where unless you understand about rent\n",
      "\n",
      "control you'll be surprised to hear I still had my apartment, sealed\n",
      "\n",
      "up like a tomb of my old life. Idelle was in New York at least, and\n",
      "\n",
      "there were other people trying to paint there, even though I didn't\n",
      "\n",
      "know any of them.When I got back to New York I resumed my old life, except now I was\n",
      "\n",
      "rich. It was as weird as it sounds. I resumed all my old patterns,\n",
      "\n",
      "except now there were doors where there hadn't been. Now when I was\n",
      "\n",
      "tired of walking, all I had to do was raise my hand, and (unless\n",
      "\n",
      "it was raining) a taxi would stop to pick me up. Now when I walked\n",
      "\n",
      "past charming little restaurants I could go in and order lunch. It\n",
      "\n",
      "was exciting for a while. Painting started to go better. I experimented\n",
      "\n",
      "with a new kind of still life where I'd paint one painting in the\n",
      "\n",
      "old way, then photograph it and print it, blown up, on canvas, and\n",
      "\n",
      "then use that as the underpainting for a second still life, painted\n",
      "\n",
      "from the same objects (which hopefully hadn't rotted yet).Meanwhile I looked for an apartment to buy. Now I could actually\n",
      "\n",
      "choose what neighborhood to live in. Where, I asked myself and\n",
      "\n",
      "various real estate agents, is the Cambridge of New York? Aided by\n",
      "\n",
      "occasional visits to actual Cambridge, I gradually realized there\n",
      "\n",
      "wasn't one. Huh.Around this time, in the spring of 2000, I had an idea. It was clear\n",
      "\n",
      "from our experience with Viaweb that web apps were the future. Why\n",
      "\n",
      "not build a web app for making web apps? Why not let people edit\n",
      "\n",
      "code on our server through the browser, and then host the resulting\n",
      "\n",
      "applications for them?\n",
      "\n",
      "[9]\n",
      "\n",
      "You could run all sorts of services\n",
      "\n",
      "on the servers that these applications could use just by making an\n",
      "\n",
      "API call: making and receiving phone calls, manipulating images,\n",
      "\n",
      "taking credit card payments, etc.I got so excited about this idea that I couldn't think about anything\n",
      "\n",
      "else. It seemed obvious that this was the future. I didn't particularly\n",
      "\n",
      "want to start another company, but it was clear that this idea would\n",
      "\n",
      "have to be embodied as one, so I decided to move to Cambridge and\n",
      "\n",
      "start it. I hoped to lure Robert into working on it with me, but\n",
      "\n",
      "there I ran into a hitch. Robert was now a postdoc at MIT, and\n",
      "\n",
      "though he'd made a lot of money the last time I'd lured him into\n",
      "\n",
      "working on one of my schemes, it had also been a huge time sink.\n",
      "\n",
      "So while he agreed that it sounded like a plausible idea, he firmly\n",
      "\n",
      "refused to work on it.Hmph. Well, I'd do it myself then. I recruited Dan Giffin, who had\n",
      "\n",
      "worked for Viaweb, and two undergrads who wanted summer jobs, and\n",
      "\n",
      "we got to work trying to build what it's now clear is about twenty\n",
      "\n",
      "companies and several open source projects worth of software. The\n",
      "\n",
      "language for defining applications would of course be a dialect of\n",
      "\n",
      "Lisp. But I wasn't so naive as to assume I could spring an overt\n",
      "\n",
      "Lisp on a general audience; we'd hide the parentheses, like Dylan\n",
      "\n",
      "did.By then there was a name for the kind of company Viaweb was, an\n",
      "\n",
      "\"application service provider,\" or ASP. This name didn't last long\n",
      "\n",
      "before it was replaced by \"software as a service,\" but it was current\n",
      "\n",
      "for long enough that I named this new company after it: it was going\n",
      "\n",
      "to be called Aspra.I started working on the application builder, Dan worked on network\n",
      "\n",
      "infrastructure, and the two undergrads worked on the first two\n",
      "\n",
      "services (images and phone calls). But about halfway through the\n",
      "\n",
      "summer I realized I really didn't want to run a company  especially\n",
      "\n",
      "not a big one, which it was looking like this would have to be. I'd\n",
      "\n",
      "only started Viaweb because I needed the money. Now that I didn't\n",
      "\n",
      "need money anymore, why was I doing this? If this vision had to be\n",
      "\n",
      "realized as a company, then screw the vision. I'd build a subset\n",
      "\n",
      "that could be done as an open source project.Much to my surprise, the time I spent working on this stuff was not\n",
      "\n",
      "wasted after all. After we started Y Combinator, I would often\n",
      "\n",
      "encounter startups working on parts of this new architecture, and\n",
      "\n",
      "it was very useful to have spent so much time thinking about it and\n",
      "\n",
      "even trying to write some of it.The subset I would build as an open source project was the new Lisp,\n",
      "\n",
      "whose parentheses I now wouldn't even have to hide. A lot of Lisp\n",
      "\n",
      "hackers dream of building a new Lisp, partly because one of the\n",
      "\n",
      "distinctive features of the language is that it has dialects, and\n",
      "\n",
      "partly, I think, because we have in our minds a Platonic form of\n",
      "\n",
      "Lisp that all existing dialects fall short of. I certainly did. So\n",
      "\n",
      "at the end of the summer Dan and I switched to working on this new\n",
      "\n",
      "dialect of Lisp, which I called Arc, in a house I bought in Cambridge.The following spring, lightning struck. I was invited to give a\n",
      "\n",
      "talk at a Lisp conference, so I gave one about how we'd used Lisp\n",
      "\n",
      "at Viaweb. Afterward I put a postscript file of this talk online,\n",
      "\n",
      "on paulgraham.com, which I'd created years before using Viaweb but\n",
      "\n",
      "had never used for anything. In one day it got 30,000 page views.\n",
      "\n",
      "What on earth had happened? The referring urls showed that someone\n",
      "\n",
      "had posted it on Slashdot.\n",
      "\n",
      "[10]Wow, I thought, there's an audience. If I write something and put\n",
      "\n",
      "it on the web, anyone can read it. That may seem obvious now, but\n",
      "\n",
      "it was surprising then. In the print era there was a narrow channel\n",
      "\n",
      "to readers, guarded by fierce monsters known as editors. The only\n",
      "\n",
      "way to get an audience for anything you wrote was to get it published\n",
      "\n",
      "as a book, or in a newspaper or magazine. Now anyone could publish\n",
      "\n",
      "anything.This had been possible in principle since 1993, but not many people\n",
      "\n",
      "had realized it yet. I had been intimately involved with building\n",
      "\n",
      "the infrastructure of the web for most of that time, and a writer\n",
      "\n",
      "as well, and it had taken me 8 years to realize it. Even then it\n",
      "\n",
      "took me several years to understand the implications. It meant there\n",
      "\n",
      "would be a whole new generation of\n",
      "\n",
      "essays.\n",
      "\n",
      "[11]In the print era, the channel for publishing essays had been\n",
      "\n",
      "vanishingly small. Except for a few officially anointed thinkers\n",
      "\n",
      "who went to the right parties in New York, the only people allowed\n",
      "\n",
      "to publish essays were specialists writing about their specialties.\n",
      "\n",
      "There were so many essays that had never been written, because there\n",
      "\n",
      "had been no way to publish them. Now they could be, and I was going\n",
      "\n",
      "to write them.\n",
      "\n",
      "[12]I've worked on several different things, but to the extent there\n",
      "\n",
      "was a turning point where I figured out what to work on, it was\n",
      "\n",
      "when I started publishing essays online. From then on I knew that\n",
      "\n",
      "whatever else I did, I'd always write essays too.I knew that online essays would be a\n",
      "\n",
      "marginal medium at first.\n",
      "\n",
      "Socially they'd seem more like rants posted by nutjobs on their\n",
      "\n",
      "GeoCities sites than the genteel and beautifully typeset compositions\n",
      "\n",
      "published in The New Yorker. But by this point I knew enough to\n",
      "\n",
      "find that encouraging instead of discouraging.One of the most conspicuous patterns I've noticed in my life is how\n",
      "\n",
      "well it has worked, for me at least, to work on things that weren't\n",
      "\n",
      "prestigious. Still life has always been the least prestigious form\n",
      "\n",
      "of painting. Viaweb and Y Combinator both seemed lame when we started\n",
      "\n",
      "them. I still get the glassy eye from strangers when they ask what\n",
      "\n",
      "I'm writing, and I explain that it's an essay I'm going to publish\n",
      "\n",
      "on my web site. Even Lisp, though prestigious intellectually in\n",
      "\n",
      "something like the way Latin is, also seems about as hip.It's not that unprestigious types of work are good per se. But when\n",
      "\n",
      "you find yourself drawn to some kind of work despite its current\n",
      "\n",
      "lack of prestige, it's a sign both that there's something real to\n",
      "\n",
      "be discovered there, and that you have the right kind of motives.\n",
      "\n",
      "Impure motives are a big danger for the ambitious. If anything is\n",
      "\n",
      "going to lead you astray, it will be the desire to impress people.\n",
      "\n",
      "So while working on things that aren't prestigious doesn't guarantee\n",
      "\n",
      "you're on the right track, it at least guarantees you're not on the\n",
      "\n",
      "most common type of wrong one.Over the next several years I wrote lots of essays about all kinds\n",
      "\n",
      "of different topics. O'Reilly reprinted a collection of them as a\n",
      "\n",
      "book, called Hackers & Painters after one of the essays in it. I\n",
      "\n",
      "also worked on spam filters, and did some more painting. I used to\n",
      "\n",
      "have dinners for a group of friends every thursday night, which\n",
      "\n",
      "taught me how to cook for groups. And I bought another building in\n",
      "\n",
      "Cambridge, a former candy factory (and later, twas said, porn\n",
      "\n",
      "studio), to use as an office.One night in October 2003 there was a big party at my house. It was\n",
      "\n",
      "a clever idea of my friend Maria Daniels, who was one of the thursday\n",
      "\n",
      "diners. Three separate hosts would all invite their friends to one\n",
      "\n",
      "party. So for every guest, two thirds of the other guests would be\n",
      "\n",
      "people they didn't know but would probably like. One of the guests\n",
      "\n",
      "was someone I didn't know but would turn out to like a lot: a woman\n",
      "\n",
      "called Jessica Livingston. A couple days later I asked her out.Jessica was in charge of marketing at a Boston investment bank.\n",
      "\n",
      "This bank thought it understood startups, but over the next year,\n",
      "\n",
      "as she met friends of mine from the startup world, she was surprised\n",
      "\n",
      "how different reality was. And how colorful their stories were. So\n",
      "\n",
      "she decided to compile a book of\n",
      "\n",
      "interviews with startup founders.When the bank had financial problems and she had to fire half her\n",
      "\n",
      "staff, she started looking for a new job. In early 2005 she interviewed\n",
      "\n",
      "for a marketing job at a Boston VC firm. It took them weeks to make\n",
      "\n",
      "up their minds, and during this time I started telling her about\n",
      "\n",
      "all the things that needed to be fixed about venture capital. They\n",
      "\n",
      "should make a larger number of smaller investments instead of a\n",
      "\n",
      "handful of giant ones, they should be funding younger, more technical\n",
      "\n",
      "founders instead of MBAs, they should let the founders remain as\n",
      "\n",
      "CEO, and so on.One of my tricks for writing essays had always been to give talks.\n",
      "\n",
      "The prospect of having to stand up in front of a group of people\n",
      "\n",
      "and tell them something that won't waste their time is a great\n",
      "\n",
      "spur to the imagination. When the Harvard Computer Society, the\n",
      "\n",
      "undergrad computer club, asked me to give a talk, I decided I would\n",
      "\n",
      "tell them how to start a startup. Maybe they'd be able to avoid the\n",
      "\n",
      "worst of the mistakes we'd made.So I gave this talk, in the course of which I told them that the\n",
      "\n",
      "best sources of seed funding were successful startup founders,\n",
      "\n",
      "because then they'd be sources of advice too. Whereupon it seemed\n",
      "\n",
      "they were all looking expectantly at me. Horrified at the prospect\n",
      "\n",
      "of having my inbox flooded by business plans (if I'd only known),\n",
      "\n",
      "I blurted out \"But not me!\" and went on with the talk. But afterward\n",
      "\n",
      "it occurred to me that I should really stop procrastinating about\n",
      "\n",
      "angel investing. I'd been meaning to since Yahoo bought us, and now\n",
      "\n",
      "it was 7 years later and I still hadn't done one angel investment.Meanwhile I had been scheming with Robert and Trevor about projects\n",
      "\n",
      "we could work on together. I missed working with them, and it seemed\n",
      "\n",
      "like there had to be something we could collaborate on.As Jessica and I were walking home from dinner on March 11, at the\n",
      "\n",
      "corner of Garden and Walker streets, these three threads converged.\n",
      "\n",
      "Screw the VCs who were taking so long to make up their minds. We'd\n",
      "\n",
      "start our own investment firm and actually implement the ideas we'd\n",
      "\n",
      "been talking about. I'd fund it, and Jessica could quit her job and\n",
      "\n",
      "work for it, and we'd get Robert and Trevor as partners too.\n",
      "\n",
      "[13]Once again, ignorance worked in our favor. We had no idea how to\n",
      "\n",
      "be angel investors, and in Boston in 2005 there were no Ron Conways\n",
      "\n",
      "to learn from. So we just made what seemed like the obvious choices,\n",
      "\n",
      "and some of the things we did turned out to be novel.There are multiple components to Y Combinator, and we didn't figure\n",
      "\n",
      "them all out at once. The part we got first was to be an angel firm.\n",
      "\n",
      "In those days, those two words didn't go together. There were VC\n",
      "\n",
      "firms, which were organized companies with people whose job it was\n",
      "\n",
      "to make investments, but they only did big, million dollar investments.\n",
      "\n",
      "And there were angels, who did smaller investments, but these were\n",
      "\n",
      "individuals who were usually focused on other things and made\n",
      "\n",
      "investments on the side. And neither of them helped founders enough\n",
      "\n",
      "in the beginning. We knew how helpless founders were in some respects,\n",
      "\n",
      "because we remembered how helpless we'd been. For example, one thing\n",
      "\n",
      "Julian had done for us that seemed to us like magic was to get us\n",
      "\n",
      "set up as a company. We were fine writing fairly difficult software,\n",
      "\n",
      "but actually getting incorporated, with bylaws and stock and all\n",
      "\n",
      "that stuff, how on earth did you do that? Our plan was not only to\n",
      "\n",
      "make seed investments, but to do for startups everything Julian had\n",
      "\n",
      "done for us.YC was not organized as a fund. It was cheap enough to run that we\n",
      "\n",
      "funded it with our own money. That went right by 99% of readers,\n",
      "\n",
      "but professional investors are thinking \"Wow, that means they got\n",
      "\n",
      "all the returns.\" But once again, this was not due to any particular\n",
      "\n",
      "insight on our part. We didn't know how VC firms were organized.\n",
      "\n",
      "It never occurred to us to try to raise a fund, and if it had, we\n",
      "\n",
      "wouldn't have known where to start.\n",
      "\n",
      "[14]The most distinctive thing about YC is the batch model: to fund a\n",
      "\n",
      "bunch of startups all at once, twice a year, and then to spend three\n",
      "\n",
      "months focusing intensively on trying to help them. That part we\n",
      "\n",
      "discovered by accident, not merely implicitly but explicitly due\n",
      "\n",
      "to our ignorance about investing. We needed to get experience as\n",
      "\n",
      "investors. What better way, we thought, than to fund a whole bunch\n",
      "\n",
      "of startups at once? We knew undergrads got temporary jobs at tech\n",
      "\n",
      "companies during the summer. Why not organize a summer program where\n",
      "\n",
      "they'd start startups instead? We wouldn't feel guilty for being\n",
      "\n",
      "in a sense fake investors, because they would in a similar sense\n",
      "\n",
      "be fake founders. So while we probably wouldn't make much money out\n",
      "\n",
      "of it, we'd at least get to practice being investors on them, and\n",
      "\n",
      "they for their part would probably have a more interesting summer\n",
      "\n",
      "than they would working at Microsoft.We'd use the building I owned in Cambridge as our headquarters.\n",
      "\n",
      "We'd all have dinner there once a week  on tuesdays, since I was\n",
      "\n",
      "already cooking for the thursday diners on thursdays  and after\n",
      "\n",
      "dinner we'd bring in experts on startups to give talks.We knew undergrads were deciding then about summer jobs, so in a\n",
      "\n",
      "matter of days we cooked up something we called the Summer Founders\n",
      "\n",
      "Program, and I posted an\n",
      "\n",
      "announcement\n",
      "\n",
      "on my site, inviting undergrads\n",
      "\n",
      "to apply. I had never imagined that writing essays would be a way\n",
      "\n",
      "to get \"deal flow,\" as investors call it, but it turned out to be\n",
      "\n",
      "the perfect source.\n",
      "\n",
      "[15]\n",
      "\n",
      "We got 225 applications for the Summer\n",
      "\n",
      "Founders Program, and we were surprised to find that a lot of them\n",
      "\n",
      "were from people who'd already graduated, or were about to that\n",
      "\n",
      "spring. Already this SFP thing was starting to feel more serious\n",
      "\n",
      "than we'd intended.We invited about 20 of the 225 groups to interview in person, and\n",
      "\n",
      "from those we picked 8 to fund. They were an impressive group. That\n",
      "\n",
      "first batch included reddit, Justin Kan and Emmett Shear, who went\n",
      "\n",
      "on to found Twitch, Aaron Swartz, who had already helped write the\n",
      "\n",
      "RSS spec and would a few years later become a martyr for open access,\n",
      "\n",
      "and Sam Altman, who would later become the second president of YC.\n",
      "\n",
      "I don't think it was entirely luck that the first batch was so good.\n",
      "\n",
      "You had to be pretty bold to sign up for a weird thing like the\n",
      "\n",
      "Summer Founders Program instead of a summer job at a legit place\n",
      "\n",
      "like Microsoft or Goldman Sachs.The deal for startups was based on a combination of the deal we did\n",
      "\n",
      "with Julian ($10k for 10%) and what Robert said MIT grad students\n",
      "\n",
      "got for the summer ($6k). We invested $6k per founder, which in the\n",
      "\n",
      "typical two-founder case was $12k, in return for 6%. That had to\n",
      "\n",
      "be fair, because it was twice as good as the deal we ourselves had\n",
      "\n",
      "taken. Plus that first summer, which was really hot, Jessica brought\n",
      "\n",
      "the founders free air conditioners.\n",
      "\n",
      "[16]Fairly quickly I realized that we had stumbled upon the way to scale\n",
      "\n",
      "startup funding. Funding startups in batches was more convenient\n",
      "\n",
      "for us, because it meant we could do things for a lot of startups\n",
      "\n",
      "at once, but being part of a batch was better for the startups too.\n",
      "\n",
      "It solved one of the biggest problems faced by founders: the\n",
      "\n",
      "isolation. Now you not only had colleagues, but colleagues who\n",
      "\n",
      "understood the problems you were facing and could tell you how they\n",
      "\n",
      "were solving them.As YC grew, we started to notice other advantages of scale. The\n",
      "\n",
      "alumni became a tight community, dedicated to helping one another,\n",
      "\n",
      "and especially the current batch, whose shoes they remembered being\n",
      "\n",
      "in. We also noticed that the startups were becoming one another's\n",
      "\n",
      "customers. We used to refer jokingly to the \"YC GDP,\" but as YC\n",
      "\n",
      "grows this becomes less and less of a joke. Now lots of startups\n",
      "\n",
      "get their initial set of customers almost entirely from among their\n",
      "\n",
      "batchmates.I had not originally intended YC to be a full-time job. I was going\n",
      "\n",
      "to do three things: hack, write essays, and work on YC. As YC grew,\n",
      "\n",
      "and I grew more excited about it, it started to take up a lot more\n",
      "\n",
      "than a third of my attention. But for the first few years I was\n",
      "\n",
      "still able to work on other things.In the summer of 2006, Robert and I started working on a new version\n",
      "\n",
      "of Arc. This one was reasonably fast, because it was compiled into\n",
      "\n",
      "Scheme. To test this new Arc, I wrote Hacker News in it. It was\n",
      "\n",
      "originally meant to be a news aggregator for startup founders and\n",
      "\n",
      "was called Startup News, but after a few months I got tired of\n",
      "\n",
      "reading about nothing but startups. Plus it wasn't startup founders\n",
      "\n",
      "we wanted to reach. It was future startup founders. So I changed\n",
      "\n",
      "the name to Hacker News and the topic to whatever engaged one's\n",
      "\n",
      "intellectual curiosity.HN was no doubt good for YC, but it was also by far the biggest\n",
      "\n",
      "source of stress for me. If all I'd had to do was select and help\n",
      "\n",
      "founders, life would have been so easy. And that implies that HN\n",
      "\n",
      "was a mistake. Surely the biggest source of stress in one's work\n",
      "\n",
      "should at least be something close to the core of the work. Whereas\n",
      "\n",
      "I was like someone who was in pain while running a marathon not\n",
      "\n",
      "from the exertion of running, but because I had a blister from an\n",
      "\n",
      "ill-fitting shoe. When I was dealing with some urgent problem during\n",
      "\n",
      "YC, there was about a 60% chance it had to do with HN, and a 40%\n",
      "\n",
      "chance it had do with everything else combined.\n",
      "\n",
      "[17]As well as HN, I wrote all of YC's internal software in Arc. But\n",
      "\n",
      "while I continued to work a good deal in Arc, I gradually stopped\n",
      "\n",
      "working on Arc, partly because I didn't have time to, and partly\n",
      "\n",
      "because it was a lot less attractive to mess around with the language\n",
      "\n",
      "now that we had all this infrastructure depending on it. So now my\n",
      "\n",
      "three projects were reduced to two: writing essays and working on\n",
      "\n",
      "YC.YC was different from other kinds of work I've done. Instead of\n",
      "\n",
      "deciding for myself what to work on, the problems came to me. Every\n",
      "\n",
      "6 months there was a new batch of startups, and their problems,\n",
      "\n",
      "whatever they were, became our problems. It was very engaging work,\n",
      "\n",
      "because their problems were quite varied, and the good founders\n",
      "\n",
      "were very effective. If you were trying to learn the most you could\n",
      "\n",
      "about startups in the shortest possible time, you couldn't have\n",
      "\n",
      "picked a better way to do it.There were parts of the job I didn't like. Disputes between cofounders,\n",
      "\n",
      "figuring out when people were lying to us, fighting with people who\n",
      "\n",
      "maltreated the startups, and so on. But I worked hard even at the\n",
      "\n",
      "parts I didn't like. I was haunted by something Kevin Hale once\n",
      "\n",
      "said about companies: \"No one works harder than the boss.\" He meant\n",
      "\n",
      "it both descriptively and prescriptively, and it was the second\n",
      "\n",
      "part that scared me. I wanted YC to be good, so if how hard I worked\n",
      "\n",
      "set the upper bound on how hard everyone else worked, I'd better\n",
      "\n",
      "work very hard.One day in 2010, when he was visiting California for interviews,\n",
      "\n",
      "Robert Morris did something astonishing: he offered me unsolicited\n",
      "\n",
      "advice. I can only remember him doing that once before. One day at\n",
      "\n",
      "Viaweb, when I was bent over double from a kidney stone, he suggested\n",
      "\n",
      "that it would be a good idea for him to take me to the hospital.\n",
      "\n",
      "That was what it took for Rtm to offer unsolicited advice. So I\n",
      "\n",
      "remember his exact words very clearly. \"You know,\" he said, \"you\n",
      "\n",
      "should make sure Y Combinator isn't the last cool thing you do.\"At the time I didn't understand what he meant, but gradually it\n",
      "\n",
      "dawned on me that he was saying I should quit. This seemed strange\n",
      "\n",
      "advice, because YC was doing great. But if there was one thing rarer\n",
      "\n",
      "than Rtm offering advice, it was Rtm being wrong. So this set me\n",
      "\n",
      "thinking. It was true that on my current trajectory, YC would be\n",
      "\n",
      "the last thing I did, because it was only taking up more of my\n",
      "\n",
      "attention. It had already eaten Arc, and was in the process of\n",
      "\n",
      "eating essays too. Either YC was my life's work or I'd have to leave\n",
      "\n",
      "eventually. And it wasn't, so I would.In the summer of 2012 my mother had a stroke, and the cause turned\n",
      "\n",
      "out to be a blood clot caused by colon cancer. The stroke destroyed\n",
      "\n",
      "her balance, and she was put in a nursing home, but she really\n",
      "\n",
      "wanted to get out of it and back to her house, and my sister and I\n",
      "\n",
      "were determined to help her do it. I used to fly up to Oregon to\n",
      "\n",
      "visit her regularly, and I had a lot of time to think on those\n",
      "\n",
      "flights. On one of them I realized I was ready to hand YC over to\n",
      "\n",
      "someone else.I asked Jessica if she wanted to be president, but she didn't, so\n",
      "\n",
      "we decided we'd try to recruit Sam Altman. We talked to Robert and\n",
      "\n",
      "Trevor and we agreed to make it a complete changing of the guard.\n",
      "\n",
      "Up till that point YC had been controlled by the original LLC we\n",
      "\n",
      "four had started. But we wanted YC to last for a long time, and to\n",
      "\n",
      "do that it couldn't be controlled by the founders. So if Sam said\n",
      "\n",
      "yes, we'd let him reorganize YC. Robert and I would retire, and\n",
      "\n",
      "Jessica and Trevor would become ordinary partners.When we asked Sam if he wanted to be president of YC, initially he\n",
      "\n",
      "said no. He wanted to start a startup to make nuclear reactors.\n",
      "\n",
      "But I kept at it, and in October 2013 he finally agreed. We decided\n",
      "\n",
      "he'd take over starting with the winter 2014 batch. For the rest\n",
      "\n",
      "of 2013 I left running YC more and more to Sam, partly so he could\n",
      "\n",
      "learn the job, and partly because I was focused on my mother, whose\n",
      "\n",
      "cancer had returned.She died on January 15, 2014. We knew this was coming, but it was\n",
      "\n",
      "still hard when it did.I kept working on YC till March, to help get that batch of startups\n",
      "\n",
      "through Demo Day, then I checked out pretty completely. (I still\n",
      "\n",
      "talk to alumni and to new startups working on things I'm interested\n",
      "\n",
      "in, but that only takes a few hours a week.)What should I do next? Rtm's advice hadn't included anything about\n",
      "\n",
      "that. I wanted to do something completely different, so I decided\n",
      "\n",
      "I'd paint. I wanted to see how good I could get if I really focused\n",
      "\n",
      "on it. So the day after I stopped working on YC, I started painting.\n",
      "\n",
      "I was rusty and it took a while to get back into shape, but it was\n",
      "\n",
      "at least completely engaging.\n",
      "\n",
      "[18]I spent most of the rest of 2014 painting. I'd never been able to\n",
      "\n",
      "work so uninterruptedly before, and I got to be better than I had\n",
      "\n",
      "been. Not good enough, but better. Then in November, right in the\n",
      "\n",
      "middle of a painting, I ran out of steam. Up till that point I'd\n",
      "\n",
      "always been curious to see how the painting I was working on would\n",
      "\n",
      "turn out, but suddenly finishing this one seemed like a chore. So\n",
      "\n",
      "I stopped working on it and cleaned my brushes and haven't painted\n",
      "\n",
      "since. So far anyway.I realize that sounds rather wimpy. But attention is a zero sum\n",
      "\n",
      "game. If you can choose what to work on, and you choose a project\n",
      "\n",
      "that's not the best one (or at least a good one) for you, then it's\n",
      "\n",
      "getting in the way of another project that is. And at 50 there was\n",
      "\n",
      "some opportunity cost to screwing around.I started writing essays again, and wrote a bunch of new ones over\n",
      "\n",
      "the next few months. I even wrote a couple that\n",
      "\n",
      "weren't about\n",
      "\n",
      "startups. Then in March 2015 I started working on Lisp again.The distinctive thing about Lisp is that its core is a language\n",
      "\n",
      "defined by writing an interpreter in itself. It wasn't originally\n",
      "\n",
      "intended as a programming language in the ordinary sense. It was\n",
      "\n",
      "meant to be a formal model of computation, an alternative to the\n",
      "\n",
      "Turing machine. If you want to write an interpreter for a language\n",
      "\n",
      "in itself, what's the minimum set of predefined operators you need?\n",
      "\n",
      "The Lisp that John McCarthy invented, or more accurately discovered,\n",
      "\n",
      "is an answer to that question.\n",
      "\n",
      "[19]McCarthy didn't realize this Lisp could even be used to program\n",
      "\n",
      "computers till his grad student Steve Russell suggested it. Russell\n",
      "\n",
      "translated McCarthy's interpreter into IBM 704 machine language,\n",
      "\n",
      "and from that point Lisp started also to be a programming language\n",
      "\n",
      "in the ordinary sense. But its origins as a model of computation\n",
      "\n",
      "gave it a power and elegance that other languages couldn't match.\n",
      "\n",
      "It was this that attracted me in college, though I didn't understand\n",
      "\n",
      "why at the time.McCarthy's 1960 Lisp did nothing more than interpret Lisp expressions.\n",
      "\n",
      "It was missing a lot of things you'd want in a programming language.\n",
      "\n",
      "So these had to be added, and when they were, they weren't defined\n",
      "\n",
      "using McCarthy's original axiomatic approach. That wouldn't have\n",
      "\n",
      "been feasible at the time. McCarthy tested his interpreter by\n",
      "\n",
      "hand-simulating the execution of programs. But it was already getting\n",
      "\n",
      "close to the limit of interpreters you could test that way  indeed,\n",
      "\n",
      "there was a bug in it that McCarthy had overlooked. To test a more\n",
      "\n",
      "complicated interpreter, you'd have had to run it, and computers\n",
      "\n",
      "then weren't powerful enough.Now they are, though. Now you could continue using McCarthy's\n",
      "\n",
      "axiomatic approach till you'd defined a complete programming language.\n",
      "\n",
      "And as long as every change you made to McCarthy's Lisp was a\n",
      "\n",
      "discoveredness-preserving transformation, you could, in principle,\n",
      "\n",
      "end up with a complete language that had this quality. Harder to\n",
      "\n",
      "do than to talk about, of course, but if it was possible in principle,\n",
      "\n",
      "why not try? So I decided to take a shot at it. It took 4 years,\n",
      "\n",
      "from March 26, 2015 to October 12, 2019. It was fortunate that I\n",
      "\n",
      "had a precisely defined goal, or it would have been hard to keep\n",
      "\n",
      "at it for so long.I wrote this new Lisp, called Bel,\n",
      "\n",
      "in itself in Arc. That may sound\n",
      "\n",
      "like a contradiction, but it's an indication of the sort of trickery\n",
      "\n",
      "I had to engage in to make this work. By means of an egregious\n",
      "\n",
      "collection of hacks I managed to make something close enough to an\n",
      "\n",
      "interpreter written in itself that could actually run. Not fast,\n",
      "\n",
      "but fast enough to test.I had to ban myself from writing essays during most of this time,\n",
      "\n",
      "or I'd never have finished. In late 2015 I spent 3 months writing\n",
      "\n",
      "essays, and when I went back to working on Bel I could barely\n",
      "\n",
      "understand the code. Not so much because it was badly written as\n",
      "\n",
      "because the problem is so convoluted. When you're working on an\n",
      "\n",
      "interpreter written in itself, it's hard to keep track of what's\n",
      "\n",
      "happening at what level, and errors can be practically encrypted\n",
      "\n",
      "by the time you get them.So I said no more essays till Bel was done. But I told few people\n",
      "\n",
      "about Bel while I was working on it. So for years it must have\n",
      "\n",
      "seemed that I was doing nothing, when in fact I was working harder\n",
      "\n",
      "than I'd ever worked on anything. Occasionally after wrestling for\n",
      "\n",
      "hours with some gruesome bug I'd check Twitter or HN and see someone\n",
      "\n",
      "asking \"Does Paul Graham still code?\"Working on Bel was hard but satisfying. I worked on it so intensively\n",
      "\n",
      "that at any given time I had a decent chunk of the code in my head\n",
      "\n",
      "and could write more there. I remember taking the boys to the\n",
      "\n",
      "coast on a sunny day in 2015 and figuring out how to deal with some\n",
      "\n",
      "problem involving continuations while I watched them play in the\n",
      "\n",
      "tide pools. It felt like I was doing life right. I remember that\n",
      "\n",
      "because I was slightly dismayed at how novel it felt. The good news\n",
      "\n",
      "is that I had more moments like this over the next few years.In the summer of 2016 we moved to England. We wanted our kids to\n",
      "\n",
      "see what it was like living in another country, and since I was a\n",
      "\n",
      "British citizen by birth, that seemed the obvious choice. We only\n",
      "\n",
      "meant to stay for a year, but we liked it so much that we still\n",
      "\n",
      "live there. So most of Bel was written in England.In the fall of 2019, Bel was finally finished. Like McCarthy's\n",
      "\n",
      "original Lisp, it's a spec rather than an implementation, although\n",
      "\n",
      "like McCarthy's Lisp it's a spec expressed as code.Now that I could write essays again, I wrote a bunch about topics\n",
      "\n",
      "I'd had stacked up. I kept writing essays through 2020, but I also\n",
      "\n",
      "started to think about other things I could work on. How should I\n",
      "\n",
      "choose what to do? Well, how had I chosen what to work on in the\n",
      "\n",
      "past? I wrote an essay for myself to answer that question, and I\n",
      "\n",
      "was surprised how long and messy the answer turned out to be. If\n",
      "\n",
      "this surprised me, who'd lived it, then I thought perhaps it would\n",
      "\n",
      "be interesting to other people, and encouraging to those with\n",
      "\n",
      "similarly messy lives. So I wrote a more detailed version for others\n",
      "\n",
      "to read, and this is the last sentence of it.\n",
      "\n",
      "Notes[1]\n",
      "\n",
      "My experience skipped a step in the evolution of computers:\n",
      "\n",
      "time-sharing machines with interactive OSes. I went straight from\n",
      "\n",
      "batch processing to microcomputers, which made microcomputers seem\n",
      "\n",
      "all the more exciting.[2]\n",
      "\n",
      "Italian words for abstract concepts can nearly always be\n",
      "\n",
      "predicted from their English cognates (except for occasional traps\n",
      "\n",
      "like polluzione). It's the everyday words that differ. So if you\n",
      "\n",
      "string together a lot of abstract concepts with a few simple verbs,\n",
      "\n",
      "you can make a little Italian go a long way.[3]\n",
      "\n",
      "I lived at Piazza San Felice 4, so my walk to the Accademia\n",
      "\n",
      "went straight down the spine of old Florence: past the Pitti, across\n",
      "\n",
      "the bridge, past Orsanmichele, between the Duomo and the Baptistery,\n",
      "\n",
      "and then up Via Ricasoli to Piazza San Marco. I saw Florence at\n",
      "\n",
      "street level in every possible condition, from empty dark winter\n",
      "\n",
      "evenings to sweltering summer days when the streets were packed with\n",
      "\n",
      "tourists.[4]\n",
      "\n",
      "You can of course paint people like still lives if you want\n",
      "\n",
      "to, and they're willing. That sort of portrait is arguably the apex\n",
      "\n",
      "of still life painting, though the long sitting does tend to produce\n",
      "\n",
      "pained expressions in the sitters.[5]\n",
      "\n",
      "Interleaf was one of many companies that had smart people and\n",
      "\n",
      "built impressive technology, and yet got crushed by Moore's Law.\n",
      "\n",
      "In the 1990s the exponential growth in the power of commodity (i.e.\n",
      "\n",
      "Intel) processors rolled up high-end, special-purpose hardware and\n",
      "\n",
      "software companies like a bulldozer.[6]\n",
      "\n",
      "The signature style seekers at RISD weren't specifically\n",
      "\n",
      "mercenary. In the art world, money and coolness are tightly coupled.\n",
      "\n",
      "Anything expensive comes to be seen as cool, and anything seen as\n",
      "\n",
      "cool will soon become equally expensive.[7]\n",
      "\n",
      "Technically the apartment wasn't rent-controlled but\n",
      "\n",
      "rent-stabilized, but this is a refinement only New Yorkers would\n",
      "\n",
      "know or care about. The point is that it was really cheap, less\n",
      "\n",
      "than half market price.[8]\n",
      "\n",
      "Most software you can launch as soon as it's done. But when\n",
      "\n",
      "the software is an online store builder and you're hosting the\n",
      "\n",
      "stores, if you don't have any users yet, that fact will be painfully\n",
      "\n",
      "obvious. So before we could launch publicly we had to launch\n",
      "\n",
      "privately, in the sense of recruiting an initial set of users and\n",
      "\n",
      "making sure they had decent-looking stores.[9]\n",
      "\n",
      "We'd had a code editor in Viaweb for users to define their\n",
      "\n",
      "own page styles. They didn't know it, but they were editing Lisp\n",
      "\n",
      "expressions underneath. But this wasn't an app editor, because the\n",
      "\n",
      "code ran when the merchants' sites were generated, not when shoppers\n",
      "\n",
      "visited them.[10]\n",
      "\n",
      "This was the first instance of what is now a familiar experience,\n",
      "\n",
      "and so was what happened next, when I read the comments and found\n",
      "\n",
      "they were full of angry people. How could I claim that Lisp was\n",
      "\n",
      "better than other languages? Weren't they all Turing complete?\n",
      "\n",
      "People who see the responses to essays I write sometimes tell me\n",
      "\n",
      "how sorry they feel for me, but I'm not exaggerating when I reply\n",
      "\n",
      "that it has always been like this, since the very beginning. It\n",
      "\n",
      "comes with the territory. An essay must tell readers things they\n",
      "\n",
      "don't already know, and some\n",
      "\n",
      "people dislike being told such things.[11]\n",
      "\n",
      "People put plenty of stuff on the internet in the 90s of\n",
      "\n",
      "course, but putting something online is not the same as publishing\n",
      "\n",
      "it online. Publishing online means you treat the online version as\n",
      "\n",
      "the (or at least a) primary version.[12]\n",
      "\n",
      "There is a general lesson here that our experience with Y\n",
      "\n",
      "Combinator also teaches: Customs continue to constrain you long\n",
      "\n",
      "after the restrictions that caused them have disappeared. Customary\n",
      "\n",
      "VC practice had once, like the customs about publishing essays,\n",
      "\n",
      "been based on real constraints. Startups had once been much more\n",
      "\n",
      "expensive to start, and proportionally rare. Now they could be cheap\n",
      "\n",
      "and common, but the VCs' customs still reflected the old world,\n",
      "\n",
      "just as customs about writing essays still reflected the constraints\n",
      "\n",
      "of the print era.Which in turn implies that people who are independent-minded (i.e.\n",
      "\n",
      "less influenced by custom) will have an advantage in fields affected\n",
      "\n",
      "by rapid change (where customs are more likely to be obsolete).Here's an interesting point, though: you can't always predict which\n",
      "\n",
      "fields will be affected by rapid change. Obviously software and\n",
      "\n",
      "venture capital will be, but who would have predicted that essay\n",
      "\n",
      "writing would be?[13]\n",
      "\n",
      "Y Combinator was not the original name. At first we were\n",
      "\n",
      "called Cambridge Seed. But we didn't want a regional name, in case\n",
      "\n",
      "someone copied us in Silicon Valley, so we renamed ourselves after\n",
      "\n",
      "one of the coolest tricks in the lambda calculus, the Y combinator.I picked orange as our color partly because it's the warmest, and\n",
      "\n",
      "partly because no VC used it. In 2005 all the VCs used staid colors\n",
      "\n",
      "like maroon, navy blue, and forest green, because they were trying\n",
      "\n",
      "to appeal to LPs, not founders. The YC logo itself is an inside\n",
      "\n",
      "joke: the Viaweb logo had been a white V on a red circle, so I made\n",
      "\n",
      "the YC logo a white Y on an orange square.[14]\n",
      "\n",
      "YC did become a fund for a couple years starting in 2009,\n",
      "\n",
      "because it was getting so big I could no longer afford to fund it\n",
      "\n",
      "personally. But after Heroku got bought we had enough money to go\n",
      "\n",
      "back to being self-funded.[15]\n",
      "\n",
      "I've never liked the term \"deal flow,\" because it implies\n",
      "\n",
      "that the number of new startups at any given time is fixed. This\n",
      "\n",
      "is not only false, but it's the purpose of YC to falsify it, by\n",
      "\n",
      "causing startups to be founded that would not otherwise have existed.[16]\n",
      "\n",
      "She reports that they were all different shapes and sizes,\n",
      "\n",
      "because there was a run on air conditioners and she had to get\n",
      "\n",
      "whatever she could, but that they were all heavier than she could\n",
      "\n",
      "carry now.[17]\n",
      "\n",
      "Another problem with HN was a bizarre edge case that occurs\n",
      "\n",
      "when you both write essays and run a forum. When you run a forum,\n",
      "\n",
      "you're assumed to see if not every conversation, at least every\n",
      "\n",
      "conversation involving you. And when you write essays, people post\n",
      "\n",
      "highly imaginative misinterpretations of them on forums. Individually\n",
      "\n",
      "these two phenomena are tedious but bearable, but the combination\n",
      "\n",
      "is disastrous. You actually have to respond to the misinterpretations,\n",
      "\n",
      "because the assumption that you're present in the conversation means\n",
      "\n",
      "that not responding to any sufficiently upvoted misinterpretation\n",
      "\n",
      "reads as a tacit admission that it's correct. But that in turn\n",
      "\n",
      "encourages more; anyone who wants to pick a fight with you senses\n",
      "\n",
      "that now is their chance.[18]\n",
      "\n",
      "The worst thing about leaving YC was not working with Jessica\n",
      "\n",
      "anymore. We'd been working on YC almost the whole time we'd known\n",
      "\n",
      "each other, and we'd neither tried nor wanted to separate it from\n",
      "\n",
      "our personal lives, so leaving was like pulling up a deeply rooted\n",
      "\n",
      "tree.[19]\n",
      "\n",
      "One way to get more precise about the concept of invented vs\n",
      "\n",
      "discovered is to talk about space aliens. Any sufficiently advanced\n",
      "\n",
      "alien civilization would certainly know about the Pythagorean\n",
      "\n",
      "theorem, for example. I believe, though with less certainty, that\n",
      "\n",
      "they would also know about the Lisp in McCarthy's 1960 paper.But if so there's no reason to suppose that this is the limit of\n",
      "\n",
      "the language that might be known to them. Presumably aliens need\n",
      "\n",
      "numbers and errors and I/O too. So it seems likely there exists at\n",
      "\n",
      "least one path out of McCarthy's Lisp along which discoveredness\n",
      "\n",
      "is preserved.Thanks to Trevor Blackwell, John Collison, Patrick Collison, Daniel\n",
      "\n",
      "Gackle, Ralph Hazell, Jessica Livingston, Robert Morris, and Harj\n",
      "\n",
      "Taggar for reading drafts of this.\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n"
     ]
    },
    {
     "ename": "InvalidRequestError",
     "evalue": "This model's maximum context length is 4097 tokens, however you requested 19068 tokens (18812 in your prompt; 256 for the completion). Please reduce your prompt; or completion length.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mInvalidRequestError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m/var/folders/5c/csjfqsk97xz704h7v3fzjqph0000gn/T/ipykernel_4303/3610895313.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mchain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlg_doc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/base.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m    237\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    238\u001b[0m                 \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"`run` supports only one positional argument.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 239\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moutput_keys\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    240\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    241\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mkwargs\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/base.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs, return_only_outputs)\u001b[0m\n\u001b[1;32m    140\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    141\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallback_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_chain_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 142\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    143\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallback_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_chain_end\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    144\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprep_outputs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreturn_only_outputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/base.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs, return_only_outputs)\u001b[0m\n\u001b[1;32m    137\u001b[0m         )\n\u001b[1;32m    138\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 139\u001b[0;31m             \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    140\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    141\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallback_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_chain_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/combine_documents/base.py\u001b[0m in \u001b[0;36m_call\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m     54\u001b[0m         \u001b[0;31m# Other keys are assumed to be needed for LLM prediction\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     55\u001b[0m         \u001b[0mother_keys\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mv\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mk\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minput_key\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 56\u001b[0;31m         \u001b[0moutput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mextra_return_dict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcombine_docs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdocs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mother_keys\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     57\u001b[0m         \u001b[0mextra_return_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moutput_key\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     58\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mextra_return_dict\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/combine_documents/stuff.py\u001b[0m in \u001b[0;36mcombine_docs\u001b[0;34m(self, docs, **kwargs)\u001b[0m\n\u001b[1;32m     87\u001b[0m         \u001b[0minputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_inputs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdocs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     88\u001b[0m         \u001b[0;31m# Call predict on the LLM.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 89\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mllm_chain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     90\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     91\u001b[0m     async def acombine_docs(\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/llm.py\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m    151\u001b[0m                 \u001b[0mcompletion\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mllm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0madjective\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"funny\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    152\u001b[0m         \"\"\"\n\u001b[0;32m--> 153\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moutput_key\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    154\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    155\u001b[0m     \u001b[0;32masync\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mapredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/base.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs, return_only_outputs)\u001b[0m\n\u001b[1;32m    140\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    141\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallback_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_chain_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 142\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    143\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallback_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_chain_end\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    144\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprep_outputs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreturn_only_outputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/base.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs, return_only_outputs)\u001b[0m\n\u001b[1;32m    137\u001b[0m         )\n\u001b[1;32m    138\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 139\u001b[0;31m             \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    140\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    141\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallback_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_chain_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/llm.py\u001b[0m in \u001b[0;36m_call\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m    132\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    133\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 134\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    135\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    136\u001b[0m     \u001b[0;32masync\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_acall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/llm.py\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self, input_list)\u001b[0m\n\u001b[1;32m    115\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput_list\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    116\u001b[0m         \u001b[0;34m\"\"\"Utilize the LLM generate method for speed gains.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 117\u001b[0;31m         \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgenerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_list\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    118\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_outputs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    119\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/chains/llm.py\u001b[0m in \u001b[0;36mgenerate\u001b[0;34m(self, input_list)\u001b[0m\n\u001b[1;32m     57\u001b[0m         \u001b[0;34m\"\"\"Generate LLM result from inputs.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     58\u001b[0m         \u001b[0mprompts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstop\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprep_prompts\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_list\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 59\u001b[0;31m         \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mllm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgenerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprompts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstop\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstop\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     60\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     61\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/llms/base.py\u001b[0m in \u001b[0;36mgenerate\u001b[0;34m(self, prompts, stop)\u001b[0m\n\u001b[1;32m    126\u001b[0m             \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    127\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallback_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_llm_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 128\u001b[0;31m                 \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    129\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallback_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_llm_end\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    130\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/llms/base.py\u001b[0m in \u001b[0;36mgenerate\u001b[0;34m(self, prompts, stop)\u001b[0m\n\u001b[1;32m    123\u001b[0m             )\n\u001b[1;32m    124\u001b[0m             \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 125\u001b[0;31m                 \u001b[0moutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_generate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprompts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstop\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstop\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    126\u001b[0m             \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    127\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallback_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_llm_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/llms/openai.py\u001b[0m in \u001b[0;36m_generate\u001b[0;34m(self, prompts, stop)\u001b[0m\n\u001b[1;32m    257\u001b[0m                 \u001b[0mchoices\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mextend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"choices\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    258\u001b[0m             \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 259\u001b[0;31m                 \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompletion_with_retry\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprompt\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0m_prompts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    260\u001b[0m                 \u001b[0mchoices\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mextend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"choices\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    261\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstreaming\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/llms/openai.py\u001b[0m in \u001b[0;36mcompletion_with_retry\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m    204\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    205\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 206\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0m_completion_with_retry\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    207\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    208\u001b[0m     \u001b[0;32masync\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0macompletion_with_retry\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/tenacity/__init__.py\u001b[0m in \u001b[0;36mwrapped_f\u001b[0;34m(*args, **kw)\u001b[0m\n\u001b[1;32m    287\u001b[0m         \u001b[0;34m@\u001b[0m\u001b[0mfunctools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwraps\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    288\u001b[0m         \u001b[0;32mdef\u001b[0m \u001b[0mwrapped_f\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAny\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAny\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAny\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 289\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    290\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    291\u001b[0m         \u001b[0;32mdef\u001b[0m \u001b[0mretry_with\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAny\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAny\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mWrappedFn\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/tenacity/__init__.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m    377\u001b[0m         \u001b[0mretry_state\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mRetryCallState\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mretry_object\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    378\u001b[0m         \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 379\u001b[0;31m             \u001b[0mdo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mretry_state\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mretry_state\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    380\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdo\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mDoAttempt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    381\u001b[0m                 \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/tenacity/__init__.py\u001b[0m in \u001b[0;36miter\u001b[0;34m(self, retry_state)\u001b[0m\n\u001b[1;32m    312\u001b[0m         \u001b[0mis_explicit_retry\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfut\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfailed\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfut\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mTryAgain\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    313\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mis_explicit_retry\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mretry\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mretry_state\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 314\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mfut\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    315\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    316\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mafter\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/concurrent/futures/_base.py\u001b[0m in \u001b[0;36mresult\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m    437\u001b[0m                     \u001b[0;32mraise\u001b[0m \u001b[0mCancelledError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    438\u001b[0m                 \u001b[0;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_state\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mFINISHED\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 439\u001b[0;31m                     \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__get_result\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    440\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    441\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_condition\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/concurrent/futures/_base.py\u001b[0m in \u001b[0;36m__get_result\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    389\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_exception\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    390\u001b[0m             \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 391\u001b[0;31m                 \u001b[0;32mraise\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_exception\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    392\u001b[0m             \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    393\u001b[0m                 \u001b[0;31m# Break a reference cycle with the exception in self._exception\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/tenacity/__init__.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m    380\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdo\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mDoAttempt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    381\u001b[0m                 \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 382\u001b[0;31m                     \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    383\u001b[0m                 \u001b[0;32mexcept\u001b[0m \u001b[0mBaseException\u001b[0m\u001b[0;34m:\u001b[0m  \u001b[0;31m# noqa: B902\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    384\u001b[0m                     \u001b[0mretry_state\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_exception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m  \u001b[0;31m# type: ignore[arg-type]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/langchain/llms/openai.py\u001b[0m in \u001b[0;36m_completion_with_retry\u001b[0;34m(**kwargs)\u001b[0m\n\u001b[1;32m    202\u001b[0m         \u001b[0;34m@\u001b[0m\u001b[0mretry_decorator\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    203\u001b[0m         \u001b[0;32mdef\u001b[0m \u001b[0m_completion_with_retry\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 204\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    205\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    206\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0m_completion_with_retry\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/openai/api_resources/completion.py\u001b[0m in \u001b[0;36mcreate\u001b[0;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m     23\u001b[0m         \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     24\u001b[0m             \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 25\u001b[0;31m                 \u001b[0;32mreturn\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     26\u001b[0m             \u001b[0;32mexcept\u001b[0m \u001b[0mTryAgain\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     27\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0mstart\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/openai/api_resources/abstract/engine_api_resource.py\u001b[0m in \u001b[0;36mcreate\u001b[0;34m(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)\u001b[0m\n\u001b[1;32m    151\u001b[0m         )\n\u001b[1;32m    152\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 153\u001b[0;31m         response, _, api_key = requestor.request(\n\u001b[0m\u001b[1;32m    154\u001b[0m             \u001b[0;34m\"post\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    155\u001b[0m             \u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/openai/api_requestor.py\u001b[0m in \u001b[0;36mrequest\u001b[0;34m(self, method, url, params, headers, files, stream, request_id, request_timeout)\u001b[0m\n\u001b[1;32m    225\u001b[0m             \u001b[0mrequest_timeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrequest_timeout\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    226\u001b[0m         )\n\u001b[0;32m--> 227\u001b[0;31m         \u001b[0mresp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgot_stream\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_interpret_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstream\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    228\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mresp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgot_stream\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapi_key\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    229\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/openai/api_requestor.py\u001b[0m in \u001b[0;36m_interpret_response\u001b[0;34m(self, result, stream)\u001b[0m\n\u001b[1;32m    618\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    619\u001b[0m             return (\n\u001b[0;32m--> 620\u001b[0;31m                 self._interpret_response_line(\n\u001b[0m\u001b[1;32m    621\u001b[0m                     \u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcontent\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"utf-8\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    622\u001b[0m                     \u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatus_code\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/openai/api_requestor.py\u001b[0m in \u001b[0;36m_interpret_response_line\u001b[0;34m(self, rbody, rcode, rheaders, stream)\u001b[0m\n\u001b[1;32m    678\u001b[0m         \u001b[0mstream_error\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstream\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;34m\"error\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mresp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    679\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mstream_error\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;36m200\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0mrcode\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0;36m300\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 680\u001b[0;31m             raise self.handle_error_response(\n\u001b[0m\u001b[1;32m    681\u001b[0m                 \u001b[0mrbody\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrcode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrheaders\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstream_error\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstream_error\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    682\u001b[0m             )\n",
      "\u001b[0;31mInvalidRequestError\u001b[0m: This model's maximum context length is 4097 tokens, however you requested 19068 tokens (18812 in your prompt; 256 for the completion). Please reduce your prompt; or completion length."
     ]
    }
   ],
   "source": [
    "chain.run(lg_doc)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7bc1482",
   "metadata": {},
   "source": [
    "### Summarize: Map Reduce"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6819d5c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "chain = load_summarize_chain(llm, chain_type=\"map_reduce\", verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "57ad190a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new MapReduceDocumentsChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"The winter glory of the Sierra ! How little is known of it! Californians admire descriptions of the Swiss Alps, reading with breathless interest how ice and snow load their sublime heights, and booming avalanches sweep in glorious array through their crowded forests, while our own icy, snow-laden mountains, with their unrivaled forests, loom unnoticed along our eastern horizon. True, only mountaineers may penetrate their snow-blocked fastnesses to behold them in all their white wild grandeur, but to every healthy man and woman, and even to children, many of the subalpine valleys and lake-basins, six or seven thousand feet above the sea, remain invitingly open and approachable all winter. With a friend and his two little sons I have just returned from a week of bracing weathering around Lake Tahoe, in which we enjoyed glorious views of winter, fine rolling and sliding in the snow, swimming in the icy lake, and lusty reviving exercise on snow-shoes that kept our pulses dancing right merrily. All the weather was hearty and exhilarating, though varying almost from hour to hour: snowing, blowing, clear and cloudy, but never rigorously cold.\n",
      "\n",
      "This winter has been remarkably mild, the mercury having seldom made a very near approach to zero, even during the coldest nights around the lake, while the average noonday temperature was considerably above the freezing- point. The snow lies deep on the surrounding mountains and about the shores, solid white contrasting with the dark-blue water of the lake, while the forests and canons and the upper glacial fountain hollows are well filled, assuring abundance of summer water for the lakes and streams.\n",
      "\n",
      "According to the record kept by Mr. McKinney, on the west shore of the lake, eight miles above Tahoe City, at an elevation of 6,500 feet above sea-level, the amount of snow, measured as it fell, was twenty-two feet and four inches for the season up to March 20th, with four inches of rain, while an inch or two more of rain and two or three feet of snow will probably fall before the full opening of spring. Last season the snowfall, measured by the same observer, at the same station, was only nine feet and seven inches, while the season before last it was no less than forty seven feet and six inches. The fall about Yosemite Valley, according to my own observations, usually considerably exceeded this. The greater portion of the snow that loads the main summits of the range falls in small crisp flakes and broken crystals; or when accompanied by strong winds at a low temperature, the crystals, instead of being locked together in tufted flakes, are driven against each other and broken into meal and fine dust which darkens the sky like night But down in the forested region, at about the elevation of Lake Tahoe, the greater portion comes gently to the ground, light and feathery, some of the flakes in mild weather being nearly an inch in diameter, and is evenly distributed and kept from drifting to any great extent by Lake Tahoe in Winter. 121 the shelter of the woods. Every tree is loaded with the fairy bloom, bending down the branches, and hushing the singing of the elastic needles. When the storm is over and the sun shines, the dazzling snow at once begins to settle and shift and fall off the trees in miniature avalanches; then the relieved branches spring up and shake themselves dry, and the whole green forest, fed and refreshed, waves and sings again rejoicing. The snow on the ground settles also, and thaws and freezes until it becomes coarsely granulated ice, with all trace of its crystalline snow structure destroyed. This is the present condition of most of the snow on the range. From towards midnight until midday at this time of year a man may walk firmly over the surface, as if on ice, provided the preceding day has been warm and the night frosty.\n",
      "\n",
      "The forested region up to an elevation of about eight thousand feet is generally clear of snow towards the end of May or middle of June; but now (March 28th) the higher canons are still heavily blocked, and the head tributaries of the rivers flow in dark tunnels beneath the icy mass. As warm summer advances, the roof of compacted snow falls in here and there, leaving magnificent arching bridges where it is strongest, over which one may safely ride a horse. All the upper streams are thus buried and bridged every winter, and are seldom completely opened to the light before the end of June or middle of July.\n",
      "\n",
      "Notwithstanding twenty-two feet of snow has fallen here this season, so greatly has it been melted and compacted, the present average depth at a height of 7,500 feet does not exceed seven feet. The drifts in exposed lake hollows and along the lee sides of bald ridges above the timberline are often fifty feet or more in depth, and many of the latter are grandly adorned with overcurling cornices, beneath which pale blue light shimmers with ineffable beauty. But it is in the fountain cirques of the ancient glaciers, beneath the shadows of the highest peaks, that the heaviest and most enduring deposits are stored up. For there the lavish snowfall on the steep converging slopes is shot down in avalanches during or after' every storm, heaping snow on snow to a depth of a hundred feet, or even more at times. These treasured banks are never wholly melted, however hot the summer, but with the few lingering glaciers form perennial fountains for the highest tributaries of the rivers.\n",
      "\n",
      "Few even among Californians have any fair conception of the marvelous abundance of glacier lakes hidden in the fastnesses of our mountains. The snow and some of the glaciers make a telling show, even from the distant lowlands; but not a single stream is visible, nor a hollow where one might hope to find a lake. Nevertheless, wild rivers are falling and sounding in every canon, and all their upper branches are fairly laden with lakes like orchard-trees with fruit. They nestle in rocky nooks and hollows about all the high peaks and in the larger canons, reflecting their stern, rugged beauty and giving charming animation to the bleakest and most forbidding landscapes. From the summit of Red Mountain, a day's journey to the east of Yosemite Valley, forty-two may be seen within a radius of eight or ten miles. The whole number in the Sierra can hardly be less than fifteen hundred, exclusive of the smaller gems, which are innumerable. Perhaps two-thirds of them lie on the west flank of the range, and all are restricted to the alpine and subalpine regions, those which once brightened the lower regions having long since vanished by the filling in of their basins. Lake Tahoe is king of them all, not only in size, but in the surpassing beauty of its shores and waters. It seems a kind of heaven to which the dead lakes of the lowlands had come with their best beauty spiritualized. It lies embosomed in mountains of moderate height near the northern extremity of the high portion of the Lake Tahoe in Winter. 123 range, between the main axis and a spur that puts out on the east side from near the head of the Carson River. Though it is twenty-one miles long by ten wide, and from about five hundred to sixteen hundred feet deep, its basin was once occupied by a glacier which filled it from the bottom to a point high above the present water-level, and being lavishly fed by the snows of the encompassing mountains, crawled slowly, like a mighty river, over the north rim of the basin, crushing and grinding the lower mountains that lay in its way, and it was only at the end of the ice period that this noble lake, at least in anything like its present form, came into existence.\n",
      "\n",
      "Excepting the forests that have sprung up around its shores, the post-glacial changes that have taken place are scarcely appreciable. The sediments carried forward by the inflowing streams at the head of the lake have made a few square miles of meadow-land, and the breaking through of a moraine dam in the canon of the outlet has lowered the lake considerably, leaving shore benches and lines on the rocky promontories to mark the original level. With these comparatively unimportant exceptions, the lake itself and all its grandly sculptured, ice-scored, and moraine-streaked basin exist to-day in just about the condition they presented when first they came to the light towards the close of the Glacial Period.\n",
      "\n",
      "The destructive action of man in clearing away the forests has not as yet effected any very marked change in general views. Perhaps about 150,000,000 feet of lumber for the Comstock mines has thus far been cut from the lake shores. But the business is being pushed so fervently from year to year, almost the entire basin must be stripped ere long of one of its most attractive features. One of the lumber companies at work here has contracted with mine owners to supply 36,000,000 feet of lumber and 60,000 cords of wood this season. It is estimated that the Tahoe basin still contains about 600,000,000 feet of lumber available for the mines.\n",
      "\n",
      "In summer the woods resound with the outlandish noise of loggers and choppers and screaming mills; skiffs and steamboats skim the lovely blue water in work and play; and ever and anon as you thread the groves along shore you come upon groups of gay tourists sauntering about, gathering flowers, or resting luxuriously in the rosiny shade of the pines, some in easy picnic attire, others all ribbons and colors, glaring wildly amid the green leaves and frightening the wondering squirrels and birds. But winter brings rest. At sight of the first snowflake pleasure-seekers flee as from a plague, the ax leaves the woods, and the kind snow heals every scar. Contemplating the basin from any commanding hilltop, only pale curls of smoke seen at wide intervals betoken the existence of human dwellings. Like the bears, the few settlers that remain here are silently \"holed up.\" The snow covers their cabins as if they were bowlders, and when approached only a narrow shoveled-out passage, or tunnel, is found leading to the door. Some of the more enterprising winter dwellers drift about in boats in calm weather, catching trout for the Carson market,â€”for the lake, on account of its great depth, never freezes. They thus earn from thirty to forty dollars a month, and at the same time get rid of lonely dullness. A trapper may also be seen now and then shuffling along the shore on long Norwegian snow-shoes in pursuit of minks, fishers, and otters.\n",
      "\n",
      "In this letter I intended only to say a good word for winter in the mountains, hoping to incite others to come and enjoy it, sketching our excursion to illustrate the ease and comfort with which such snowy winter rambles may be made; but I have written too much I fear about the snow to leave room for more than a thin outline. We went by rail to Lake Tahoe in Winter. 125 Carson, and from there set out by stage for Glenbrook. After ascending on wheels until we reached the snow-line, the driver attached his four horses to a sled, hoping thus to cross the summit, which is less than eight thousand feet high, without much difficulty. But mild weather had softened the snow, and the unfortunate animals, after floundering and wallowing through a mile of it, lay down exhausted with their heels in the air. Then we made our way on foot over to the lake. Next day, on a small steam-tug, we crossed the lake to McKinney's, on the west shore, where we were at home. Here we spent a few health-giving, delightful days, rowing, bathing, racing at lightning speed on snow-shoes down a mountain-side back of the house, and slipping about through the solemn, silent woods. Only the eldest of my companions ventured with me on the steep slopes. This was his first experience on snowshoes, and the several descents he made were the most remarkable specimens of falling locomotion that I ever had the fortune to witness. In shooting down steep declivities the long sled-runner-like shoes have to be kept parallel with firmly braced limbs. My friend, however, heedless of advice, launched himself in wild abandon, bouncing and diving, his limbs and shoes in chaotic entanglement, now in the snow, now in the air, whirling over and over in giddy rolls and somersaults that would shame the most extravagant performances of a circus acrobat. How original and inimitable he was! Wonderfully refreshing and exhilarating his queer capers must have been; for on coming to rest, with his runaway members divorced and lost, he would quietly gather himself, pick out the snow from his neck and ears, and say with preternatural solemnity, \"This, Muir, is the very poetry of motion.\"\n",
      "\n",
      "We also spent some rare evenings by the huge fire in McKinney's old cabin. The log walls are covered with trophies of the chase, for our host has been a great hunter in his day. Two live pet coons were frolicking on the floor while our grand old host smiled benignly and played with them, the firelight gleaming on his weathered face. How big he seems, thus brought into relief, and what a shadow he casts! The fragrant rosiny fire is the very god of the home. No wonder the old nations, with their fresher instincts, had their fireside gods. At last, when a mild snow-storm was blowing, we rowed to the lower end of the lake and completed our excursion by slipping on snow-shoes down the Truckee canon to the railroad.\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\" This article is an account of a winter excursion to Lake Tahoe in California, where the snowfall this season has been recorded at 22 feet and 4 inches. Despite the deep snow around the lake, the mild winter has kept temperatures above freezing. The post-glacial changes to the lake are minimal and the surrounding forests are still mostly intact, though logging has begun in earnest, with a contract for 96,000,000 feet of lumber and 60,000 cords of wood this season. The author recounts their adventures, including rowing, bathing, snow shoeing, and visits to old cabins. They ended the trip by snowshoeing down the Truckee canon to the railroad.\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "' This article is an account of a winter excursion to Lake Tahoe in California. Despite the deep snow, the temperatures have remained above freezing. Logging has begun in the surrounding forests, but the post-glacial changes to the lake are minimal. The author recounts their adventures, including rowing, bathing, snow shoeing, and visits to old cabins. They ended the trip by snowshoeing down the Truckee canon to the railroad.'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chain.run(sm_doc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "4898d986",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.text_splitter import RecursiveCharacterTextSplitter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "20a994e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "text_splitter = RecursiveCharacterTextSplitter(\n",
    "    # Set a really small chunk size, just to show.\n",
    "    chunk_size = 400,\n",
    "    chunk_overlap = 0\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "877728d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "lg_docs = text_splitter.split_documents(lg_doc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5ad8f7b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You have 201 document(s)\n",
      "You have roughly 12751 words in your docs\n",
      "\n",
      "Preview: \n",
      "February 2021Before college the two main things I worked on, outside of school,\n",
      "\n",
      "were writing and programming\n"
     ]
    }
   ],
   "source": [
    "doc_summary(lg_docs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "682900fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new MapReduceDocumentsChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"February 2021Before college the two main things I worked on, outside of school,\n",
      "\n",
      "were writing and programming. I didn't write essays. I wrote what\n",
      "\n",
      "beginning writers were supposed to write then, and probably still\n",
      "\n",
      "are: short stories. My stories were awful. They had hardly any plot,\n",
      "\n",
      "just characters with strong feelings, which I imagined made them\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"deep.The first programs I tried writing were on the IBM 1401 that our\n",
      "\n",
      "school district used for what was then called \"data processing.\"\n",
      "\n",
      "This was in 9th grade, so I was 13 or 14. The school district's\n",
      "\n",
      "1401 happened to be in the basement of our junior high school, and\n",
      "\n",
      "my friend Rich Draves and I got permission to use it. It was like\n",
      "\n",
      "a mini Bond villain's lair down there, with all these alien-looking\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"machines  CPU, disk drives, printer, card reader  sitting up\n",
      "\n",
      "on a raised floor under bright fluorescent lights.The language we used was an early version of Fortran. You had to\n",
      "\n",
      "type programs on punch cards, then stack them in the card reader\n",
      "\n",
      "and press a button to load the program into memory and run it. The\n",
      "\n",
      "result would ordinarily be to print something on the spectacularly\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"loud printer.I was puzzled by the 1401. I couldn't figure out what to do with\n",
      "\n",
      "it. And in retrospect there's not much I could have done with it.\n",
      "\n",
      "The only form of input to programs was data stored on punched cards,\n",
      "\n",
      "and I didn't have any data stored on punched cards. The only other\n",
      "\n",
      "option was to do things that didn't rely on any input, like calculate\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"approximations of pi, but I didn't know enough math to do anything\n",
      "\n",
      "interesting of that type. So I'm not surprised I can't remember any\n",
      "\n",
      "programs I wrote, because they can't have done much. My clearest\n",
      "\n",
      "memory is of the moment I learned it was possible for programs not\n",
      "\n",
      "to terminate, when one of mine didn't. On a machine without\n",
      "\n",
      "time-sharing, this was a social as well as a technical error, as\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"\n",
      "\n",
      "The writer talks about their experience with writing and programming before starting college. They explain that they wrote short stories but found them to be lacking in plot, and instead containing characters with strong feelings.\n",
      "\n",
      " Rich Draves and the speaker, both 13 or 14 years old, obtained permission to use the IBM 1401 in the basement of their junior high school for \"data processing\", which was the speaker's first experience with programming. The environment was described as similar to a mini Bond villain's lair.\n",
      "\n",
      " This is a description of a computing environment in the early days of computers, where programs were written in Fortran and typed on punch cards. The machines were situated on a raised floor and lit by fluorescent lights, and pressing a button would load the programs into memory and run them, resulting in something being printed on a printer.\n",
      "\n",
      " The narrator was puzzled by the 1401, a type of printer, as they had no data stored on punched cards to use as input. The only thing they could do was perform calculations that didn't require any input.\n",
      "\n",
      " This person remembers the moment they learned that programs can not terminate and the moment of surprise when one of their programs didn't terminate. They also remember attempting to approximate pi with math, but they were not successful in doing anything interesting with it.\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "\" The speaker recounts their experience of programming with the IBM 1401 in their junior high school basement, which was their first time working with computers. They describe the environment as similar to a mini Bond villain's lair, and detail their attempts to program in Fortran and approximate pi with math. They also recall the moment they learned that programs can not terminate, and their surprise when one of their programs didn't.\""
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chain.run(lg_docs[:5])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1b99505",
   "metadata": {},
   "source": [
    "### Summarize: Refine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "49b2dbfe",
   "metadata": {},
   "outputs": [],
   "source": [
    "chain = load_summarize_chain(llm, chain_type=\"refine\", verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "efadaf1b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new RefineDocumentsChain chain...\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mWrite a concise summary of the following:\n",
      "\n",
      "\n",
      "\"February 2021Before college the two main things I worked on, outside of school,\n",
      "\n",
      "were writing and programming. I didn't write essays. I wrote what\n",
      "\n",
      "beginning writers were supposed to write then, and probably still\n",
      "\n",
      "are: short stories. My stories were awful. They had hardly any plot,\n",
      "\n",
      "just characters with strong feelings, which I imagined made them\"\n",
      "\n",
      "\n",
      "CONCISE SUMMARY:\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mYour job is to produce a final summary\n",
      "We have provided an existing summary up to a certain point:  Prior to college, the author practiced writing and programming in their spare time. The author wrote short stories that lacked plot, but the characters did have strong emotions.\n",
      "We have the opportunity to refine the existing summary(only if needed) with some more context below.\n",
      "------------\n",
      "deep.The first programs I tried writing were on the IBM 1401 that our\n",
      "\n",
      "school district used for what was then called \"data processing.\"\n",
      "\n",
      "This was in 9th grade, so I was 13 or 14. The school district's\n",
      "\n",
      "1401 happened to be in the basement of our junior high school, and\n",
      "\n",
      "my friend Rich Draves and I got permission to use it. It was like\n",
      "\n",
      "a mini Bond villain's lair down there, with all these alien-looking\n",
      "------------\n",
      "Given the new context, refine the original summaryIf the context isn't useful, return the original summary.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mYour job is to produce a final summary\n",
      "We have provided an existing summary up to a certain point: \n",
      "\n",
      "Prior to college, the author practiced writing and programming in their spare time. The author wrote short stories that lacked plot, but the characters did have strong emotions. In 9th grade, the author and a friend got permission to use an IBM 1401 in the basement of their junior high school for data processing. This experience exposed the author to programming and helped to develop their skills.\n",
      "We have the opportunity to refine the existing summary(only if needed) with some more context below.\n",
      "------------\n",
      "machines  CPU, disk drives, printer, card reader  sitting up\n",
      "\n",
      "on a raised floor under bright fluorescent lights.The language we used was an early version of Fortran. You had to\n",
      "\n",
      "type programs on punch cards, then stack them in the card reader\n",
      "\n",
      "and press a button to load the program into memory and run it. The\n",
      "\n",
      "result would ordinarily be to print something on the spectacularly\n",
      "------------\n",
      "Given the new context, refine the original summaryIf the context isn't useful, return the original summary.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mYour job is to produce a final summary\n",
      "We have provided an existing summary up to a certain point: \n",
      "\n",
      "Prior to college, the author practiced writing and programming in their spare time. The author wrote short stories that lacked plot, but the characters did have strong emotions. In 9th grade, the author and a friend got permission to use an IBM 1401 in the basement of their junior high school for data processing. This experience exposed the author to programming and helped to develop their skills, using an early version of Fortran on machines such as CPU, disk drives, printer, card reader, and printing the results on the printer.\n",
      "We have the opportunity to refine the existing summary(only if needed) with some more context below.\n",
      "------------\n",
      "loud printer.I was puzzled by the 1401. I couldn't figure out what to do with\n",
      "\n",
      "it. And in retrospect there's not much I could have done with it.\n",
      "\n",
      "The only form of input to programs was data stored on punched cards,\n",
      "\n",
      "and I didn't have any data stored on punched cards. The only other\n",
      "\n",
      "option was to do things that didn't rely on any input, like calculate\n",
      "------------\n",
      "Given the new context, refine the original summaryIf the context isn't useful, return the original summary.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mYour job is to produce a final summary\n",
      "We have provided an existing summary up to a certain point: \n",
      "\n",
      "Prior to college, the author practiced writing and programming in their spare time. The author wrote short stories that lacked plot, but the characters did have strong emotions. In 9th grade, the author and a friend got permission to use an IBM 1401 in the basement of their junior high school for data processing. This experience exposed the author to programming and helped to develop their skills, using an early version of Fortran on machines such as CPU, disk drives, printer, card reader, and printing the results on the printer. The author was initially puzzled by the 1401, as the only form of input to programs was data stored on punched cards, and they had no data stored on punched cards. As a result, the author had to do things that didn't rely on any input, like calculate, in order to use the machine.\n",
      "We have the opportunity to refine the existing summary(only if needed) with some more context below.\n",
      "------------\n",
      "approximations of pi, but I didn't know enough math to do anything\n",
      "\n",
      "interesting of that type. So I'm not surprised I can't remember any\n",
      "\n",
      "programs I wrote, because they can't have done much. My clearest\n",
      "\n",
      "memory is of the moment I learned it was possible for programs not\n",
      "\n",
      "to terminate, when one of mine didn't. On a machine without\n",
      "\n",
      "time-sharing, this was a social as well as a technical error, as\n",
      "------------\n",
      "Given the new context, refine the original summaryIf the context isn't useful, return the original summary.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "\"\\n\\nPrior to college, the author practiced writing and programming in their spare time. The author wrote short stories that lacked plot, but the characters did have strong emotions. In 9th grade, the author and a friend got permission to use an IBM 1401 in the basement of their junior high school for data processing. This experience exposed the author to programming and helped to develop their skills, using an early version of Fortran on machines such as CPU, disk drives, printer, card reader, and printing the results on the printer. The author was initially puzzled by the 1401, as the only form of input to programs was data stored on punched cards, and they had no data stored on punched cards. As a result, the author had to do things that didn't rely on any input, like calculate approximations of pi, but they didn't know enough math to do anything interesting of that type. Despite this, they were able to learn that programs could fail to terminate, much to their surprise.\""
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chain.run(lg_docs[:5])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c6962c2",
   "metadata": {},
   "source": [
    "### Q&A: Map Re-Rank"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "ba864773",
   "metadata": {},
   "outputs": [],
   "source": [
    "chain = load_qa_chain(llm, chain_type=\"map_rerank\", verbose=True, return_intermediate_steps=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "6aa32765",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new MapRerankDocumentsChain chain...\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mUse the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n",
      "\n",
      "In addition to giving an answer, also return a score of how fully it answered the user's question. This should be in the following format:\n",
      "\n",
      "Question: [question here]\n",
      "Helpful Answer: [answer here]\n",
      "Score: [score between 0 and 100]\n",
      "\n",
      "How to determine the score:\n",
      "- Higher is a better answer\n",
      "- Better responds fully to the asked question, with sufficient level of detail\n",
      "- If you do not know the answer based on the context, that should be a score of 0\n",
      "- Don't be overconfident!\n",
      "\n",
      "Example #1\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Apples are red\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: red\n",
      "Score: 100\n",
      "\n",
      "Example #2\n",
      "\n",
      "Context:\n",
      "---------\n",
      "it was night and the witness forgot his glasses. he was not sure if it was a sports car or an suv\n",
      "---------\n",
      "Question: what type was the car?\n",
      "Helpful Answer: a sports car or an suv\n",
      "Score: 60\n",
      "\n",
      "Example #3\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Pears are either red or orange\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: This document does not answer the question\n",
      "Score: 0\n",
      "\n",
      "Begin!\n",
      "\n",
      "Context:\n",
      "---------\n",
      "February 2021Before college the two main things I worked on, outside of school,\n",
      "\n",
      "were writing and programming. I didn't write essays. I wrote what\n",
      "\n",
      "beginning writers were supposed to write then, and probably still\n",
      "\n",
      "are: short stories. My stories were awful. They had hardly any plot,\n",
      "\n",
      "just characters with strong feelings, which I imagined made them\n",
      "---------\n",
      "Question: Who was the authors friend who he got permission from to use the IBM 1401?\n",
      "Helpful Answer:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mUse the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n",
      "\n",
      "In addition to giving an answer, also return a score of how fully it answered the user's question. This should be in the following format:\n",
      "\n",
      "Question: [question here]\n",
      "Helpful Answer: [answer here]\n",
      "Score: [score between 0 and 100]\n",
      "\n",
      "How to determine the score:\n",
      "- Higher is a better answer\n",
      "- Better responds fully to the asked question, with sufficient level of detail\n",
      "- If you do not know the answer based on the context, that should be a score of 0\n",
      "- Don't be overconfident!\n",
      "\n",
      "Example #1\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Apples are red\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: red\n",
      "Score: 100\n",
      "\n",
      "Example #2\n",
      "\n",
      "Context:\n",
      "---------\n",
      "it was night and the witness forgot his glasses. he was not sure if it was a sports car or an suv\n",
      "---------\n",
      "Question: what type was the car?\n",
      "Helpful Answer: a sports car or an suv\n",
      "Score: 60\n",
      "\n",
      "Example #3\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Pears are either red or orange\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: This document does not answer the question\n",
      "Score: 0\n",
      "\n",
      "Begin!\n",
      "\n",
      "Context:\n",
      "---------\n",
      "deep.The first programs I tried writing were on the IBM 1401 that our\n",
      "\n",
      "school district used for what was then called \"data processing.\"\n",
      "\n",
      "This was in 9th grade, so I was 13 or 14. The school district's\n",
      "\n",
      "1401 happened to be in the basement of our junior high school, and\n",
      "\n",
      "my friend Rich Draves and I got permission to use it. It was like\n",
      "\n",
      "a mini Bond villain's lair down there, with all these alien-looking\n",
      "---------\n",
      "Question: Who was the authors friend who he got permission from to use the IBM 1401?\n",
      "Helpful Answer:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mUse the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n",
      "\n",
      "In addition to giving an answer, also return a score of how fully it answered the user's question. This should be in the following format:\n",
      "\n",
      "Question: [question here]\n",
      "Helpful Answer: [answer here]\n",
      "Score: [score between 0 and 100]\n",
      "\n",
      "How to determine the score:\n",
      "- Higher is a better answer\n",
      "- Better responds fully to the asked question, with sufficient level of detail\n",
      "- If you do not know the answer based on the context, that should be a score of 0\n",
      "- Don't be overconfident!\n",
      "\n",
      "Example #1\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Apples are red\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: red\n",
      "Score: 100\n",
      "\n",
      "Example #2\n",
      "\n",
      "Context:\n",
      "---------\n",
      "it was night and the witness forgot his glasses. he was not sure if it was a sports car or an suv\n",
      "---------\n",
      "Question: what type was the car?\n",
      "Helpful Answer: a sports car or an suv\n",
      "Score: 60\n",
      "\n",
      "Example #3\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Pears are either red or orange\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: This document does not answer the question\n",
      "Score: 0\n",
      "\n",
      "Begin!\n",
      "\n",
      "Context:\n",
      "---------\n",
      "machines  CPU, disk drives, printer, card reader  sitting up\n",
      "\n",
      "on a raised floor under bright fluorescent lights.The language we used was an early version of Fortran. You had to\n",
      "\n",
      "type programs on punch cards, then stack them in the card reader\n",
      "\n",
      "and press a button to load the program into memory and run it. The\n",
      "\n",
      "result would ordinarily be to print something on the spectacularly\n",
      "---------\n",
      "Question: Who was the authors friend who he got permission from to use the IBM 1401?\n",
      "Helpful Answer:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mUse the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n",
      "\n",
      "In addition to giving an answer, also return a score of how fully it answered the user's question. This should be in the following format:\n",
      "\n",
      "Question: [question here]\n",
      "Helpful Answer: [answer here]\n",
      "Score: [score between 0 and 100]\n",
      "\n",
      "How to determine the score:\n",
      "- Higher is a better answer\n",
      "- Better responds fully to the asked question, with sufficient level of detail\n",
      "- If you do not know the answer based on the context, that should be a score of 0\n",
      "- Don't be overconfident!\n",
      "\n",
      "Example #1\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Apples are red\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: red\n",
      "Score: 100\n",
      "\n",
      "Example #2\n",
      "\n",
      "Context:\n",
      "---------\n",
      "it was night and the witness forgot his glasses. he was not sure if it was a sports car or an suv\n",
      "---------\n",
      "Question: what type was the car?\n",
      "Helpful Answer: a sports car or an suv\n",
      "Score: 60\n",
      "\n",
      "Example #3\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Pears are either red or orange\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: This document does not answer the question\n",
      "Score: 0\n",
      "\n",
      "Begin!\n",
      "\n",
      "Context:\n",
      "---------\n",
      "loud printer.I was puzzled by the 1401. I couldn't figure out what to do with\n",
      "\n",
      "it. And in retrospect there's not much I could have done with it.\n",
      "\n",
      "The only form of input to programs was data stored on punched cards,\n",
      "\n",
      "and I didn't have any data stored on punched cards. The only other\n",
      "\n",
      "option was to do things that didn't rely on any input, like calculate\n",
      "---------\n",
      "Question: Who was the authors friend who he got permission from to use the IBM 1401?\n",
      "Helpful Answer:\u001b[0m\n",
      "Prompt after formatting:\n",
      "\u001b[32;1m\u001b[1;3mUse the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n",
      "\n",
      "In addition to giving an answer, also return a score of how fully it answered the user's question. This should be in the following format:\n",
      "\n",
      "Question: [question here]\n",
      "Helpful Answer: [answer here]\n",
      "Score: [score between 0 and 100]\n",
      "\n",
      "How to determine the score:\n",
      "- Higher is a better answer\n",
      "- Better responds fully to the asked question, with sufficient level of detail\n",
      "- If you do not know the answer based on the context, that should be a score of 0\n",
      "- Don't be overconfident!\n",
      "\n",
      "Example #1\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Apples are red\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: red\n",
      "Score: 100\n",
      "\n",
      "Example #2\n",
      "\n",
      "Context:\n",
      "---------\n",
      "it was night and the witness forgot his glasses. he was not sure if it was a sports car or an suv\n",
      "---------\n",
      "Question: what type was the car?\n",
      "Helpful Answer: a sports car or an suv\n",
      "Score: 60\n",
      "\n",
      "Example #3\n",
      "\n",
      "Context:\n",
      "---------\n",
      "Pears are either red or orange\n",
      "---------\n",
      "Question: what color are apples?\n",
      "Helpful Answer: This document does not answer the question\n",
      "Score: 0\n",
      "\n",
      "Begin!\n",
      "\n",
      "Context:\n",
      "---------\n",
      "approximations of pi, but I didn't know enough math to do anything\n",
      "\n",
      "interesting of that type. So I'm not surprised I can't remember any\n",
      "\n",
      "programs I wrote, because they can't have done much. My clearest\n",
      "\n",
      "memory is of the moment I learned it was possible for programs not\n",
      "\n",
      "to terminate, when one of mine didn't. On a machine without\n",
      "\n",
      "time-sharing, this was a social as well as a technical error, as\n",
      "---------\n",
      "Question: Who was the authors friend who he got permission from to use the IBM 1401?\n",
      "Helpful Answer:\u001b[0m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "query = \"Who was the authors friend who he got permission from to use the IBM 1401?\"\n",
    "\n",
    "result = chain({\"input_documents\": lg_docs[:5], \"question\": query}, return_only_outputs=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "32ca3629",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "' Rich Draves'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result['output_text']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "6541e14c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'answer': ' This document does not answer the question', 'score': '0'},\n",
       " {'answer': ' Rich Draves', 'score': '100'},\n",
       " {'answer': ' This document does not answer the question.', 'score': '0'},\n",
       " {'answer': ' This document does not answer the question.', 'score': '0'},\n",
       " {'answer': ' This document does not answer the question', 'score': '0'}]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result['intermediate_steps']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "be60b4e8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
